ui-select2
ui-select2 copied to clipboard
reset selection
trafficstars
Hi,
is there anyone who know how to reset a selection using the directive ?
With select2 non-angular lib, we just have to use : $(el).select2("val", "");
Thanks !
use this code in uiSelect2 directive in compile function block after return function (scope, elm, attrs, controller) {
scope.$watch(attrs['ngModel'], function (v) {
if (v === '' || v===null || v===undefined) {
var select=elm.parent().find('.select2-selection__rendered');
if(select[0]){
select[0].innerHTML='<span class="select2-selection__placeholder">'+attrs['placeholder']+'</span>'
}
}
});
...
use this code in uiSelect2 directive in compile function block after return function (scope, elm, attrs, controller) {
scope.$watch(attrs['ngModel'], function (v) { if (v === '' || v===null || v===undefined) { var select=elm.parent().find('.select2-selection__rendered'); if(select[0]){ select[0].innerHTML='<span class="select2-selection__placeholder">'+attrs['placeholder']+'</span>' } } });...
thanks