DEV Community

Discussion on: How do you build Forms?

Collapse
 
maulik profile image
Maulik

It's a bit off-topic comment but I would like to share the story
I was working on an old AngularJS(1.X) project. In that, we were manually creating forms. I had to apply dynamic validation on those forms as we fetch the validation constraints through an API request (we get constraints like max value or max length for a particular field from an API) and we also had a UI where we can change those values... So taking everything into consideration, I created a validation directive (i.e. <input custom-validator field="fieldId" ... /> ) and I have written code to fetch the constraints for particular fields in this directive and apply it to the element. (fieldId was a combination of the form entity name and the field name like ${entity_name}.${field_name} )

When we applied this dynamic validation, there were lots of forms already been there in the project without validation applied, so later I wrote a script to add this validator directive to the required fields of all forms