0

I have created a custom File-Upload control in angular material. It's working as it should except for one case. I am unable to tell the calling FormGroup about the nature of the validation error whenever one occurs.

For example, When the size of the selected file is more than allowed or the type of file selected is not acceptable.

For any of the validation errors, there is only one boolean errorState field which is letting the FormGroup know that there is an error.

How do I tell the form group about this nature of the error so that it can show an appropriate message to the user?

I have posted the code at this StackBlitz

Anup Sharma
  • 2,053
  • 20
  • 30
  • do you mean custom validator? – Eliya Cohen Aug 19 '19 at 20:49
  • @EliyaCohen There is no custom validator, Only custom control which is a file upload control. This control is being used in a formgroup. I want this control to let the formgroup know whenever there is any internal validation error. – Anup Sharma Aug 19 '19 at 21:02
  • what do you mean by "internal validation error"? – Eliya Cohen Aug 19 '19 at 21:03
  • @EliyaCohen the Custom Control is a File upload control. Users select a file of their choice. This custom control has an input control of type file. The user may select a file size greater than allowed. In that case, there is a validation failure for this custom control. I need this validation error to reach the Formgroup. – Anup Sharma Aug 19 '19 at 21:19
  • If you want that your custom control has an internal validator, you need provide NG-VALIDATORS, see, e.g. https://stackoverflow.com/questions/56576068/how-to-implement-reactive-form-as-custom-component-using-ng-value-accessor – Eliseo Aug 20 '19 at 06:50
  • @Eliseo As far as I know, it will only validate the values of the control, however, I needed to validate even before the value is generated. i.e. right when the file is selected, it needs to validate that the file is of the correct type and size then only we allow the upload process and then provide the received path as value. – Anup Sharma Aug 21 '19 at 04:36

0 Answers0