Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-blur with uib-typeahead (ui-bootstrap)

   <div class="form-group">
       <label for="Skill1">Skill</label>
       <input type="text"
        ng-model="vm.skill1" 
        name="skill1"
        uib-typeahead="skill for skill in vm.skills | filter:$viewValue"
        class="form-control typeahead"
        ng-blur="vm.checkSkills(vm.skill1)"
        placeholder="" 
        required> 
   </div>

My environment is AngularJs, I'm trying to use ng-blur only when the user leave this field, however due to the typeahead, if I use the mouse to choose an option the typeahead suggest, the ng-blur "think" I left the field and activate the ng-blur just with the first letter I emtered How can I override this?

like image 550
H. Gorodesky Avatar asked Jan 29 '26 23:01

H. Gorodesky


1 Answers

Instead of using ng-blur, required functionality can be achieved using

typeahead-on-select="checkSkills($item,$model,$label)"

HTML

<input  type="text"  ng-model="skill1" uib-typeahead="skill for skill in skills | filter:$viewValue" class="form-control typeahead" typeahead-on-select="checkSkills($item,$model,$label)"

JS

$scope.checkSkills = function(item, model, label){ 
   if(model){
      //your validation logic goes here
     // console.log (" Check skill, correctly set ", (item), model , label);
   }

 }

Plunker example : https://plnkr.co/edit/7N8TU2?p=preview

like image 86
Anil Arya Avatar answered Jan 31 '26 18:01

Anil Arya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!