Comments (5)
@Frozenfire92 I'm afraid I didn't fully understand your use case.
However, here are my thoughts on providing support for selectize events:
some of the events selectize exposes are "data-related". This may make sense for simple "jquery-based" apps. But here, we are using selectize as a view layer.
What I mean is that you should be able to handle these data related events outside of ember-selectize/selectize.
Ember-selectize will reflect whatever is in your array and selection, that is its main purpose.
Please try to make your use case more clear, ideally using an example JSBin: http://emberjs.jsbin.com/
I'm here to help!
from ember-cli-selectize.
Ok, I was afraid I wasn't being very clear.
Essentially I have an organization
with may people
. However the people aren't directly part of the organization's model in the db. Rather they are related based on the people
's organization key in their own entry in the db. Essentially I want to use selectize to add/remove people from the organization. However when removing I need to know about it so I can update that person's organization key on their model.
Does that clear things up?
Thank you!
from ember-cli-selectize.
Ok, it is clear now. You're using a multiple select, right?
Adding and removing a person from that select, sets or removes a specific organization id, right?
from ember-cli-selectize.
Here is what I would do.
Controller:
exports default Ember.Controller.extend({
selectedPeople:[],
setObservers:function(){
this.get('selectedPeople').addArrayObserver(this,{
willChange: 'selectedPeopleWillChange',
didChange: 'selectedPeopleDidChange'
});
}.on('init'),
//Will trigger when one or more people are removed
selectedPeopleWillChange:function(array, idx, removedCount){
for (var i = idx; i < idx + removedCount; i++) {
//access removed elements here through `array.objectAt(i);`
//unset your organization key here
}
},
//Will trigger when one or more people are added
selectedPeopleDidChange:function(array, idx, removedCount, addedCount){
for (var i = idx; i < idx + addedCount; i++) {
//access added elements here through `array.objectAt(i);`
//set your organization key here
}
},
});
And its template:
I think this is the kind of logic that belongs in the controller. We could use selectize's events, yes. But imagine that someday you want to revert back to vanilla selects or any other selectbox library?
This code would become untouched.
I like to think focused on the data. The view must just do its job and represent that.
I shouldn't need the view to know when my data changes.
Let me know if this worked for you.
from ember-cli-selectize.
Ok, it is clear now. You're using a multiple select, right?
Adding and removing a person from that select, sets or removes a specific organization id, right?
Correct and correct.
I won't have a chance to work on the code for a few days but I will let you know how it goes. Thank you very much for your help 😄
from ember-cli-selectize.
Related Issues (20)
- hideSelected and multiple don't work together HOT 1
- v0.5.8 broke the selectize styles HOT 4
- selectize.js:2151 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'
- multiple mode bug? HOT 2
- Selectize changing my model property to null
- Best Practice for adding/removing on a REST/API error
- add 'readOnly' to 'generalOptions ' HOT 2
- Move selectize and sifter from Bower to NPM HOT 3
- select-item action should not fire when selection promise resolves. HOT 1
- Using multiple=true with ember-changeset-validations HOT 3
- Add Support for data-dash-attributes
- Can't install due to missing dependency HOT 1
- Label truncates when second word contains letters in the first in multiple mode HOT 1
- Tooltip for list
- 2 selectors in the same template and options visible for both of them at the same time HOT 1
- Fix breaking changes in FastBoot 1.0 HOT 1
- Migration to power select HOT 1
- DEPRECATION HOT 1
- Deprecated calls to sendAction
- ember-cli-selectize triggers a Maximum Call Stack exceeded errors
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-cli-selectize.