md-autocomplete: validation not working anymore in 0.10.0
https://material.angularjs.org/0.10.0/#/demo/material.components.autocomplete, floating label demo should have validation & messages.
Thanks Rob
+1
+1
+1
+1
To fix for this is change getInputElement function
where ng-require=isRequired to @mdAutocompleteCtrl.isRequired
function getInputElement() {
if (attr.mdFloatingLabel) {
return '\
<md-input-container flex ng-if="floatingLabel">\
<label>{{floatingLabel}}</label>\
<input type="search"\
id="fl-input-{{$mdAutocompleteCtrl.id}}"\
name="{{inputName}}"\
autocomplete="off"\
ng-required="$mdAutocompleteCtrl.isRequired"\
ng-minlength="inputMinlength"\
ng-maxlength="inputMaxlength"\
ng-disabled="$mdAutocompleteCtrl.isDisabled"\
ng-model="$mdAutocompleteCtrl.scope.searchText"\
ng-keydown="$mdAutocompleteCtrl.keydown($event)"\
ng-blur="$mdAutocompleteCtrl.blur()"\
ng-focus="$mdAutocompleteCtrl.focus()"\
aria-owns="ul-{{$mdAutocompleteCtrl.id}}"\
aria-label="{{floatingLabel}}"\
aria-autocomplete="list"\
aria-haspopup="true"\
aria-activedescendant=""\
aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>\
<div md-autocomplete-parent-scope md-autocomplete-replace>' + leftover + '</div>\
</md-input-container>';
} else {
return '\
<input flex type="search"\
id="input-{{$mdAutocompleteCtrl.id}}"\
name="{{inputName}}"\
ng-if="!floatingLabel"\
autocomplete="off"\
ng-required="$mdAutocompleteCtrl.isRequired"\
ng-disabled="$mdAutocompleteCtrl.isDisabled"\
ng-model="$mdAutocompleteCtrl.scope.searchText"\
ng-keydown="$mdAutocompleteCtrl.keydown($event)"\
ng-blur="$mdAutocompleteCtrl.blur()"\
ng-focus="$mdAutocompleteCtrl.focus()"\
placeholder="{{placeholder}}"\
aria-owns="ul-{{$mdAutocompleteCtrl.id}}"\
aria-label="{{placeholder}}"\
aria-autocomplete="list"\
aria-haspopup="true"\
aria-activedescendant=""\
aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>\
<button\
type="button"\
tabindex="-1"\
ng-if="$mdAutocompleteCtrl.scope.searchText && !$mdAutocompleteCtrl.isDisabled"\
ng-click="$mdAutocompleteCtrl.clear()">\
<md-icon md-svg-icon="md-close"></md-icon>\
<span class="md-visually-hidden">Clear</span>\
</button>\
';
}
}
}
};
+1 And how to set max-length constraint on md-autocomplete?
fyi @Sriram143, looks like there's a PR in process https://github.com/angular/material/pull/3366
I solved it like this: .directive('isRequired', ['$compile', function($compile) { return { restrict: 'A', terminal: true, priority: 1000, link: function(scope, element) { element.removeAttr('is-required'); if (scope.isRequired) { element.attr('required', 'required'); } $compile(element)(scope); } }; }]) From: billy clark [email protected] To: angular/material [email protected] Cc: Mike Dobrin [email protected] Sent: Thursday, July 2, 2015 3:54 PM Subject: Re: [material] md-autocomplete: validation not working anymore in 0.10.0 (#3293)
fyi, looks like there's a PR in process #3366— Reply to this email directly or view it on GitHub.
and isRequired on the scope is set by the parent directive From: billy clark [email protected] To: angular/material [email protected] Cc: Mike Dobrin [email protected] Sent: Thursday, July 2, 2015 3:54 PM Subject: Re: [material] md-autocomplete: validation not working anymore in 0.10.0 (#3293)
fyi, looks like there's a PR in process #3366— Reply to this email directly or view it on GitHub.
This is resolved in master and will in the 0.10.1 release.
This doesn't seem to be working still.
he's my code:
<md-autocomplete required md-input-id="input_boundBallot" class="md-primary"
ng-disabled="ac.isDisabled"
md-input-name="boundStuff"
md-no-cache="ac.noCache"
md-autoselect="ac.autoSelect"
md-select-on-match="ac.selectOnMatch"
md-selected-item="ac.selectedStuff"
md-search-text-change="searchTextChange(ac.searchText)"
md-search-text="ac.searchText"
md-selected-item-change="selectedItemChange(item)"
md-items="item in searchStuff(ac.searchText)"
md-item-text="item.display"
placeholder="Select an item"
ng-value="ac.searchText"
md-min-length="0">
<md-item-template>
<span md-highlight-text="ac.searchText" md-highlight-flags="^i">{{item.display}}</span>
</md-item-template>
<md-not-found>
No matches found for "{{ac.searchText}}".
</md-not-found>
<div ng-messages="aform.boundStuff.$error">
<div ng-message="required">This field is required</div>
</div>
</md-autocomplete>
I don't think there's anything wrong with the code.
Trying with latest master 5722449b372604fc2231f73140a44094c3a94cf8
You might want to check if your aform is actually there. Print it out {{ aform.boundStuff }}