Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelcobain committed Dec 20, 2014
1 parent 9ad0a2a commit 3202ba3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ Its usage should be very similar to `Ember.Select`, but with additional features
- `placeholder` or `prompt` - Set any of these to display a text when there is no choice made. Example `"Please select an- option"`
- `disabled` - If `true` disables changes in selectize
- `multiple` - If `true` ember-selectize will enter multiple mode. `selection` is an array of options.
- `create` - if to `true` ember-selectize will enter creation mode. This allows the user to create a new item. A `create` action will be sent to the controller to let you handle the logic. You must add the item to the content array in that logic.
- `createAction` - you can customize the name of the action sent to the controller. If you set this, you don't need to set `create=true`.
- `create` - Pass a string to 'create' property to enable tag creation mode. When active, ember-selectize will send an action with that name to the application when a tag is created. The text is sent as a parameter.
- `create` - you can customize the name of the action sent to the controller. If you set this, you don't need to set `create=true`.
- `filter` - This property will have the text that the user entered to filter options. Useful for searching options in server from a large set.
- `loading` - When `true` ember-selectize adds a loading class to selectize wrapper. Just like selectize does. Then you can customize. Useful with async relationships or "finds" in Ember-Data: `loading=types.isPending`.
- `loadingClass` - Customize the loading class name. Default value: `loading`
Expand Down
16 changes: 4 additions & 12 deletions addon/components/ember-selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,10 @@ export default Ember.Component.extend({
inDOM: false,

/**
* Pass true to 'create' property to enable tag creation mode.
* When active, ember-selectize will send a 'create' action to its controller when a tag is created.
* Alternatively, you can pass a string to 'createAction' property and
* ember-selectize will activate tag creation mode send an action with that name to its controller.
* Pass a string to 'create' property to enable tag creation mode.
* When active, ember-selectize will send an action with that name to the application when a tag is created.
*/
create:false,
createAction:'create',

/**
* Loading feature default values.
Expand Down Expand Up @@ -105,12 +102,7 @@ export default Ember.Component.extend({

selectizeOptions: Ember.computed(function() {
var allowCreate = get(this, 'create');
var createAction = get(this, 'createAction');

//Normalize create property if createAction was set
if(createAction && (createAction !== 'create')){
allowCreate = true;
}
//We proxy callbacks through jQuery's 'proxy' to have the callbacks context set to 'this'
return {
plugins: this.plugins,
Expand Down Expand Up @@ -160,8 +152,8 @@ export default Ember.Component.extend({
_create:function(input,callback){
// Delete user entered text
this.selectize.setTextboxValue('');
// Send action to controller
get(this,'controller').send(get(this,'createAction'),input);
// Send create action
this.sendAction('create',input);
// We cancel the creation here, so it's up to you to include the created element
// in the content and selection property
callback(null);
Expand Down
7 changes: 6 additions & 1 deletion tests/dummy/app/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ export default Ember.Controller.extend({
id:4,
label:'Item 4'
})
]
],
actions:{
createAction:function(str){
alert(str);
}
}
});
8 changes: 5 additions & 3 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<h2 id='title'>Ember-cli-selectize</h2>
<h2 id='title'>Selectize test</h2>

{{ember-selectize
content=items
content=controller.items
optionValuePath="content.id"
optionLabelPath="content.label"
}}
selection=model.item
create="createAction"
placeholder="Select an item" }}

0 comments on commit 3202ba3

Please sign in to comment.