angularjsangularjs-validation

AngularJS Validate a json like an input


I have a form with an input that is "required". This is perfect when your value is just a text.

I also have a directive that outputs a json string. I want also to validate this json before submitting the form.

I can't create an input with this ng-model because inside that input says [Object]. Is it a good practice to stringify this json and create a custom validator that validates the json?


Solution

  • No it's not a good practice, you should not do that instead u make different inputs for different properties of JSON because stringify can't validate your JSON. Json should be either dynamically created for when the form has been submitted after validation.