-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Placeholder does not play well with required in 1.3 and ng-required in 1.2 #6
Comments
We've experienced the same issue. Because the placeholder text is being set on the element's val, the required directive sees it as a view value. So all our required inputs with placeholders are being set as valid when they aren't. |
I ended up writing a directive that overrides the angular 'required' directive and adds a situation where if the placeholder attribute is equal the viewValue (element.val()) it marks the input as invalid. |
I've changed the code in the issue-5 branch and I don't use the value in the scope any longer. Angular appears to use the scope value as the source of truth, thankfully, and so maybe this problem is resolved? I've tried the updated code in the fiddles provided and have seen the correct results. |
I assume the previous comment was meant for #5 ? |
No. It applies to this issue. As I mentioned, I don't use scope any longer. This issue cropped up because I did use scope a tiny amount. I also tested the issue-5 branch against the two fiddles mentioned at the start of this issue and I believe the code I added will solve both problems at once. |
Ah, I understand. I will try that branch tonight and get back to you. |
@fidian I have tried the issue-5 branch, and it does correct the styles issue, it does not correct the validation issue. The issue is only present on pristine forms. Before the user types anything into the form, it should be invalid because input is required. I've updated the jsfiddle provided earlier to demonstrate the difference in behavior of vanilla vs with this project included. https://jsfiddle.net/y78ohbuw/1/embedded/result/ |
In 1.3 I'd expect a required error key to be set when the input initially loads, both when using required and ng-required. Only when you type in a character and remove it will the required error key be set:
http://jsfiddle.net/eL55yebe/1/
In 1.2, using required works fine, but ng-required doesn't set the required error key:
http://jsfiddle.net/at4jkx46/
Note: in all cases, removing the placeholder directive allows the required error key to be set on load.
The text was updated successfully, but these errors were encountered: