jquery - Add new option for ui-select2 in angular js -
i using ui-select2 in angularjs uses select2 plugin of jquery. have pre-defined list , when start searching , if not found in list want add new value. doing :
var selectoptions = { formatnomatches: function(term) { return "<a ng-click=\"addcountry('abc');\">add new country</a>"; } }; $scope.addcountry = function(countryname) { console.log (' test'); };
but click doesnt work , console in addcountry never printed. idea how add new option ui-select2 in angular js ?
i've done this, not via click allowing user enter in select2 , hit enter:
<input type="text" ui-select2="selectopts" ng-model="selected"/>
in coffeescript hope idea:
$scope.selectopts = maximumselectionsize: 1 data: $scope.somelistofdata tags: true multiple: false createsearchchoice: (term) -> {id: term, text: term}
i hope puts on right track, basic thing set "tags: true"
puts select2 'tagging'mode user can add new choices , pre-existing tags provided via options attribute either
and createsearchchoice (search in http://ivaynberg.github.io/select2/ this):
creates new selectable choice user's search term. allows creation of choices not available via query function. useful when user can create choices on fly, eg 'tagging' usecase
Comments
Post a Comment