Add option to create/add new item or just listen type-text
I've added v.1.3.0 compatibility with the Forked Chosen from @koenpunt, so we're able to add/create new item.
First step is switch from oficial chosen.js
and chosen.css
to koenpunt/chosen versions.
You can download it here: https://github.com/koenpunt/chosen/releases
Then, you'll have 4 new attributes: create-option-text
, persistent-create-option
, skip-no-results
and create-option
To Create new option, use like that:
$scope.name = 'Multiple Angular Chosen Example add new option';
$scope.state = ['California', 'Arizona'];
$scope.states = [
'Alaska',
'Arizona',
'Arkansas',
'California'
];
$scope.createOption = function(term) {
$scope.$apply(function() {
$scope.states.push(term);
$scope.state.push(term);
});
}
<select multiple
chosen
create-option-text="'Create item'"
persistent-create-option="true"
skip-no-results="true"
create-option="createOption"
ng-model="state"
ng-options="s for s in states">
<option value=""></option>
</select>
Here is an example working http://plnkr.co/edit/xZ5XbO?p=preview