tillre / cores-ng

1 stars 0 forks source link

How to indicate validation error only when field is dirty #4

Open iotaweb opened 11 years ago

iotaweb commented 11 years ago

Hi Till,

Currently, the 'has-error' class is applied to fields when the form loads using the hasErrors() function. I would prefer to have the error class set only when the field is dirty.

I have tried numerous things, including extending the ng-class expression in the templates, e.g. with the String template:

<div class="form-group" ng-class="{ 'has-error': hasErrors() && modelForm.{{name}}.$dirty }">
<input class="form-control" type="text" ng-model="model" name="{{name}}">

... or something to that effect. I can't seem to get it to work, and naturally would prefer it in the validation.js service. Any ideas how to implement this?

Hope this makes some sense!

Cheers, Rob

tillre commented 11 years ago

Hi Rob,

had this in the back of my mind for some time. I think the right way would be to have a look at angulars form validation, which alreay provides ng-pristine and ng-dirty and the likes. At the time i was building this, the builtin stuff seemed to limited for my purposes, but maybe i should revisit angulars standard handling of form errors. It would be best to hook into it, which should be possible. Tell me if you got an idea how to best incorperate this. Ill get back to you when i have a better understanding of how to implement this.

Cheers

iotaweb commented 10 years ago

Thanks Till,

Yes, it would be nice if we could take advantage of the built-in validation support, particularly for the new HTML 5 input types. I'm guessing we'd need a wider range of directives to support these (or more complicated variations), so not sure to what extent it complicates the approach you've taken to date. I wish I could suggest something more meaningful, but I'm even further behind on the learning curve with angular... But in principle, I'd be keen to follow the angular-way as much as possible.

Cheers, Rob