Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

ng-minlength="1" error in form validation form.FormController #8215

Closed
rastislavcore opened this issue Jul 16, 2014 · 10 comments
Closed

ng-minlength="1" error in form validation form.FormController #8215

rastislavcore opened this issue Jul 16, 2014 · 10 comments

Comments

@rastislavcore
Copy link

When ng-minlength="1" and NO required is used on form it seems is it there bug, becouse:

ng-minlength="1" produce with no chars (<1) true in $error.minlength

@Narretz
Copy link
Contributor

Narretz commented Jul 16, 2014

This is working as expected: if the input is empty and not required, it doesn't make sense to set an error before there's actually a value. Since the minlength is 1, you'll never see an error in this case

@rastislavcore
Copy link
Author

Thank you for answer, this is now clear for me.
I have new idea for form checking, which can be useful:
There is already: $pristine, $dirty; but very useful can be $empty and $filled, which can be equal to .lengt checking.

@Narretz
Copy link
Contributor

Narretz commented Jul 17, 2014

It's possible that my comment didn't address the actual problem you describe. However, I am unable to reproduce the error: http://plnkr.co/edit/QBQz6k97msQ3lyZ21GLV?p=preview

Okay, great that I could clarify things!

@rastislavcore
Copy link
Author

Me issue is this:
http://plnkr.co/edit/4DhQhFcA3f5VeqQWWiUA?p=preview

@Narretz
Copy link
Contributor

Narretz commented Jul 17, 2014

Okay, yes that's what my explanation was about: required and min / max length work independently from each other. I guess this is solved then.

@rastislavcore
Copy link
Author

Anyway i think this is issue, becouse there isn't solution for this.

@caitp
Copy link
Contributor

caitp commented Jul 17, 2014

solution for what exactly? what exactly is the problem you're having with this? minlength=1 will not invalidate a field of length 0, because empty controls are valid --- unless required validation is used.

@rastislavcore
Copy link
Author

Ok, i will explain it:
Integrate in form validation $empty and $filled mechanism, which can easy answer if the field is blank or not. I think this can be useful for many people.

This is exactly problem for all default states. How to determine dirty empty fields in angular form validation?

@Narretz
Copy link
Contributor

Narretz commented Jul 17, 2014

Ah, I see what you mean. You want a property that reflects if there's input in the input. You can use form.myModel.$viewValue.length for that. I am not sure if it's worthwhile to have that as an extra property, even if, it needs to be seen that such a value always reflects the actual value the user sees.

@rastislavcore
Copy link
Author

Thank you, this is exactly me issue. But solved with .length.
Maybe the tip in documentation is enough for this.
Anyway solved for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants