Giter Club home page Giter Club logo

Comments (5)

miguelcobain avatar miguelcobain commented on July 19, 2024

@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.

Frozenfire92 avatar Frozenfire92 commented on July 19, 2024

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.

miguelcobain avatar miguelcobain commented on July 19, 2024

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.

miguelcobain avatar miguelcobain commented on July 19, 2024

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:

{{ember-selectize
  content=controller.people
  optionValuePath="content.id"
  optionLabelPath="content.name"
  selection=model.selectedPeople
  multiple=true
  placeholder="Select people" }}

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.

Frozenfire92 avatar Frozenfire92 commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.