Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open select programmatically

Does anyone know if it is possible to open a select programmatically in angularjs. Ive tried

angular.element(el).trigger('focus');
angular.element(el).trigger('click');
angular.element(el).trigger('mousedown');

Nothing works.

I also tried

$scope.doSomething = function(){
    setTimeout(function() {
        var el = document.getElementById('test');
        var e = document.createEvent("MouseEvents");
        e.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
        worked = el.dispatchEvent(e);
    }, 0);

}

The above set focus but do not open the select.

Is it possible?

like image 364
user727507 Avatar asked May 12 '14 12:05

user727507


1 Answers

Try this for Hover:

JS:

$(document).ready(function(){
$("#selectId").hover(function(){
   $(this)[0].size=$(this).find("option").length;
});
$("#selectId").click(function(){
   $(this)[0].size=0;
});
});

HTML:

<select id="selectId">
  <option>Volvo</option>
  <option >Saab</option>
  <option>Mercedes</option>
  <option>Audi</option>
</select>
like image 76
Prashant Kanak Avatar answered Oct 11 '22 10:10

Prashant Kanak