Nav*_*eet 6 validation angularjs material-design angular-material
如何禁用md-autocomplete中的自由文本?我希望用户只能从项目列表中进行选择,或者如果未从列表中选择项目,则根据某些验证添加ng-message.角度材料md-autocomplete演示
您可以即时将新项目添加到列表中:
<md-autocomplete flex required="required"
md-input-name="id"
md-selected-item="newItem.item"
md-search-text="itemSearch.queryText"
md-items="itemin itemSearch.querySearch()"
md-item-text="item.name"
md-input-minlength="2"
md-floating-label="enter here">
<md-item-template>
<span md-highlight-text="itemSearch.queryText"
md-highlight-flags="^i">{{item.name}}</span>
</md-item-template>
<md-not-found>
Sorry, this is not in our database
</md-not-found>
<div ng-messages="formName.id.$error">
<div ng-message="required">You must enter a name</div>
<div ng-message="minlength">You must type at least two characters</div>
</div>
</md-autocomplete>
Run Code Online (Sandbox Code Playgroud)
编辑:只需将您的消息放入其中即可<md-not-found>