indrimuska / angular-selector

A native AngularJS directive that transform a simple <select> box into a full html select with typeahead.
http://indrimuska.github.io/angular-selector
MIT License
96 stars 36 forks source link

Add option to allow user inputted tags #10

Closed kmturley closed 8 years ago

kmturley commented 8 years ago

Love this plugin, so great. Supports everything I need except for user input. It would be great to have it as an option so the user could type and when they hit Enter or comma, the custom tag would be added to the dropdown and as a select input.

I've tried to implement myself using the following:

<label for="tags">Tags</label>
<select id="tags" placeholder="Select multiple" model="tags" multi="true" selector ng-keyup="addTag($event)">
    <option value="tag1">Tag one</option>
    <option value="tag2">Tag two</option>
    <option value="tag3">Tag three</option>
</select>

Then in the controller:

scope.tags = [];
scope.addTag = function (e) {
    scope.tags.push(e.target.value);
};

However this doesn't seem to update the dropdown list. I'm going to investigate more, but you might know a better way

indrimuska commented 8 years ago

Hi @kmturley, very very good idea, tag creation would be definitely an awesome feature!

Your solution doesn't work because the select is replaced by other elements (see selector/selector.html template), one of which is a simple text input, so if you want to catch keyboard events you have to update Angular Selector from internal.

Your idea still remain interesting, you could add ng-keyup to the text input and create a method for the controller scope to support options creation.

I would like to review any PR you'll want to open, if you need help to perform this, just ask! :)

indrimuska commented 8 years ago

I'm going to close this since this feature is now available with v0.7.2. Thank you @kmturley! :)