Forgive my minimal knowledge of AngularJS and valdr...
I have an application using AngularJS where the ui is dynamically generated to edit some object with meta-data provided to determine the type to interpret the members of the object. I'm going to add extra meta-data to set validation rules for each member.
I found valdr and I wondered if it might be possible to add the rules using valdrProvider.addConstraints() called repeatedly for each editable field. Presumably the rule names would have to be made unique?
How could I remove rules from the rule set when data was unloaded?
Is this approach valid or should I just map the rule meta data directly using an AngularJS directive or something?
Your approach sounds ok. valdr offers a
removeConstraint(constraintName)function that might do what you need. Note, however, that this removes all contraints for a given model type.Take the example at https://github.com/netceteragroup/valdr#getting-started.
Calling
removeConstraint('Person')would remove all constraints forPerson. If you just want to remove thefirstNamebecause you remove the first name input field you can calladdConstraintsagain with an updated constraints definition forPerson.Final notes:
Persontypes with different implementation