angularangular-reactive-formscustom-validators

Can't validate Reactive Form with Custom Validator for input (type=['file']) max size


In short words, problem is to validate File Upload input for file max size. Angular by default isn't storing anywhere user's attached File object in Form Control. There is only value property which contains fake path for file. Ideal case should be to use Custom Validator for this purpose, but through validator function I can't get attached File object which is storing File's size. I have only access to Form Control object.

Maybe someone got similar problem previously or have any idea which could be helpful?

At the moment I am using manual File object validation on change event and manually setting/clearing attachment's errors.


Solution

  • Like I mentioned in comments, found that input's with type='file' is a weak spot in Angular forms - github.com/angular/angular.io/issues/3466 and decided to go with my described solution with manual File object validation on change event and manually setting/clearing attachment's errors.