axel-zarate / js-custom-select

Custom auto-complete select box for AngularJS and Bootstrap
MIT License
68 stars 59 forks source link

How to enable required field validation in an angularJS form? #37

Closed bhattjeet closed 8 years ago

bhattjeet commented 8 years ago

Hello All,

I need to apply ng-invalid when control value its not selected. But in that control by default set ng-valid attribute. if value is selected or not that control always set ng-valid attribute.

<div id="BranchId" class="form-control" custom-select="ser.id as ser.text for ser in vm.manifestCreateDto.branchList | filter: $searchTerm" required ng-model="vm.manifestCreateDto.branchId"></div>

i need to display RED border when value its not selected. Like below image validationimage

axel-zarate commented 8 years ago

Hi, You need to add a name attribute both to the parent form or ng-form and to the element with the custom-select directive. Then, use something like ng-class="{ 'has-error': formName.controlName.$invalid }". This behavior is not related to the custom-select itself but to the ng-model directive in conjunction with the form directive.