Completed
Last Updated: 09 Jun 2021 15:37 by ADMIN
Tim
Created on: 11 Aug 2020 16:11
Category: FileSelect
Type: Bug Report
0
FileSelect control doesn't raise form errors when restrictions violated
I'm using FileSelect as part of a reactive form.  I set file restrictions for allowedExtentions and maxFileSize.  If one of the files violate these restrictions, I would expect the form and the form control to have an error, but both are in VALID state.
3 comments
ADMIN
Georgi
Posted on: 25 Aug 2020 13:22

Hi Tim,

Тhe kendo-fileselect works like this by design. That behavior is documented here. It says:

"When the FileSelect is bound to a model through the ngModel directive, the files which do not correspond to the restrictions will not be added to the model."

If a few files are uploaded in the demo below and you take a look at myForm.value, you will see that it only contains the images that pass the restriction criteria. The formControl in the demo has the required validator, and so one image is sufficient to pass that.

https://stackblitz.com/edit/angular-8xhk5e-xpt1zm?file=app/app.component.ts

I suppose you would still like to prevent the user from submitting the form if any of the uploaded files violates the criteria. To do that, you can compare the length of your formControl's file array length and the length of actual selected images in the kendo-fileselect. You will see how that can be done in the demo above, in the save method on line 55. If the two arrays are of equal length, then all selected files satisfy the criteria.

You could go even further and create your custom validator in order to display the correct form status before "submit" has been pressed.

I hope that helps! Please do let me know if I can assist you any further.

Regards,
Georgi
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

Tim
Posted on: 18 Aug 2020 13:22
To be more specific, if you have [multiple]="true" and one of the files violates constraints, but at least one satisfies constraints, the form is valid.  I'd expect if any files violate constraints, the form would be invalid.
ADMIN
Georgi
Posted on: 18 Aug 2020 10:01

Hello Tim,

I tested the FileSelect component restrictions option, using Reactive Forms, but the form is invalid when an unallowed file extension (or file size exceed the required) is tried to be uploaded:

Please try to upload PNG file:

https://stackblitz.com/edit/angular-8xhk5e?file=app/app.component.ts

A working StackBlitz that reproduces the issue would work best. Please update the above demo to a state that reproduces the reported issue in order to provide better assistance on this case.

Looking forward to hearing from you.

Regards,
Georgi
Progress Telerik