It is possible, but it requires some workarounds. You basically do a manual check in selectedItemChange and searchTextChange .
function searchTextChange(text) { self.form.id.$error.stateMissing = true; $log.info('Text changed to ' + text); } function selectedItemChange(item) { $log.info(self.form.id); if (item === null) { $log.info('invalid'); } else { $log.info('valid'); delete self.form.id.$error.stateMissing; self.form.id.$validate(); } }
The error is set in the stateMissing property, and then used in the ng-message markup. It is important to set the form name so that you can reference the form in your controller.
<form name="ctrl.form" novalidate> <p>Use <code>md-autocomplete</code> to search for matches from local or remote data sources.</p> <md-autocomplete md-autoselect md-select-on-focus md-floating-label="Select a state" ng-disabled="ctrl.isDisabled" cache="ctrl.noCache" md-selected-item="ctrl.selectedItem" md-input-name="id" md-search-text-change="ctrl.searchTextChange(ctrl.searchText)" md-search-text="ctrl.searchText" md-items="item in ctrl.querySearch(ctrl.searchText)" md-item-text="item.display" md-min-length="0" md-selected-item-change="ctrl.selectedItemChange(ctrl.selectedItem)"> <md-item-template> <span md-highlight-text="ctrl.searchText" md-highlight-flags="^i">{{item.display}}</span> </md-item-template> <md-not-found> No states matching "{{ctrl.searchText}}" were found. <a ng-click="ctrl.newState(ctrl.searchText)">Create a new one!</a> </md-not-found> <div ng-messages="ctrl.form.id.$error"> <div ng-message="stateMissing">You must select a state</div> </div> </md-autocomplete>
http://codepen.io/kuhnroyal/pen/eZXXVr
source share