Skip to content

Instantly share code, notes, and snippets.

@deitch
Created January 24, 2015 16:31
Show Gist options
  • Save deitch/e4abbaeeaca7b0d66fcf to your computer and use it in GitHub Desktop.
Save deitch/e4abbaeeaca7b0d66fcf to your computer and use it in GitHub Desktop.
// directive
.directive('resetSearchModel',function () {
return {
restrict: 'A',
require: ['^ngModel','uiSelect'],
link: function (scope, element, attrs, ctrls) {
if (attrs.resetSearchModel === "true" || attrs.resetSearchModel === true) {
scope.$watch(attrs.ngModel,function (newval,oldval,scope) {
scope.$select.selected = undefined;
});
}
}
};
})
// sample usage - see: 'reset-search-model="true"'
<ui-select ng-model="myModel" theme="bootstrap" on-select="searchselect($item)" reset-search-input="true" reset-search-model="true">
<ui-select-match placeholder="Search...">{{$select.selected.name}}</ui-select-match>
<ui-select-choices refresh="search({val:$select.search})" refresh-delay="300" repeat="item in results">
<div ng-bind="item.name"></div>
</ui-select-choices>
</ui-select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment