required validator not working anymore
Hi, the "required" validator does not work anymore in 1.0.0-rc7 (it was working in rc4). You can find below an example (extract from the autocomplete demo page) http://codepen.io/anon/pen/VeLQEv
In this example it is not working neither for the input (of type text) nor for the autocomplete
Thanks
Behavior has changed in the latest release (rc7), see this commit for more details: https://github.com/angular/material/commit/cf7f21aa
Changelog: https://github.com/angular/material/blob/master/CHANGELOG.md
Yes I have noticed ! But it is not the problem. I just found it :-) It is only related to the required "validator" You now have to put required="true" instead of just required. The new behavior (introduced by rc7) is cool. I could remove my hack to touch the form to display it even if the form is "untouched" and add a ng-show="![form].[name].$valid" on the "ng-messages" div.
@bOOm-X it was an issue for me, I tried with ng-show="![form].[name].$dirty" and I didn't really like the result although it works.
Will give it a try :wink:
On the other hand, I didn't have to add required="true" on my inputs. Just require still works for me with rc7 :pensive:
Hi,
I will try to summarize what I want, what I can get (and how in rc7), and what I would like to have !
-
first I am dealing with form including autocomplete and "classical" input.
-
the only validator that I use is the "required" one
-
I want to display my mandatory input fields in the error state (due to the required) even if the fields have not been "touched" (I do not really understand why we should differentiate the "touched"/ "untouched" state form an UX point of view).
-
with the following normal input field I get exactly what I want with:
<md-input-container class="md-block" md-is-error="![form].myName.$valid"> <label>my label</label> <input required type="text" name="myName" ...> <div ng-messages="[form].myName.$error" ng-if="![form].myName.$valid"> <div ng-message="required">This is required.</div> </div> </md-input-container> -
with the autocomplete
<md-autocomplete required="true" md-input-name="myName" md-floating-label="myLabel" ...>
<md-item-template>
<span md-highlight-text="..." md-highlight-flags="i">{{...}}</span>
</md-item-template>
<md-not-found>No matches found.</md-not-found>
<div ng-messages="[form].myName.$error" ng-if="![form].myName.$valid">
<div ng-message="required">This is required.</div>
</div>
</md-autocomplete>
- First i need to put
required="true", if i put justrequiredthe validator does not seems to work - What I get: When the field is "untouched" the field is not in "error mode" (the base line is still grey) but the message is correctly print. When I touched the field, the "error mode" become "active" (the bottom ligne is now red). What is missing is the md-is-error of the imput container on the md-autocomplete (or be able to put a md-autocomplete in a md-input-container as for normal input. it would be more coherent in my mind)