Custom control not validating
It also registers that directive as a NG_VALIDATOR, which adds our validator to the collection of existing ones (like required or pattern for instance).Now I can define a form and make my validator apply to a text input: And that’s it!The input parameter is a form control, and the output is either an error object or null if the value is valid.So here is what that method would look like: The above code defines our directive that implements the Validator interface.This post will go over how to create a custom input component which supports validation and is compatible with both ng Model forms and Reactive Forms.As an example we will create a custom textarea component, where the validation checks that the user input is a valid JSON string.With a passion for Angular, Type Script and Java Script, Todd leads the online courses creation and has written hundreds of articles on front-end web development and beyond.He specialises in breaking down complex topics and understands the critical mission of learning new technology fast, comprehensively and the right way.
Everything I used from the demo works fine but I ran into a problem with validation.
Form validation is always a hot topic whenever I teach Angular.
People usually ask me whether they should use Template driven forms or Reactive forms, and I used to tell them that reactive forms are a better option when you need custom validators.
Unlike the demo I'm using some controls that can only be validated using a custom validator function (Rad Editor and Rad Rating).
At first, I put the functions in the user control (ascx file) but this is obviously not the thing to do because I got an error when the functions were called saying that they were undefined.