dimanche 3 avril 2016

Recommended way to handle dependent selects for creating and updating

The following will only populate a select tag with options based on the integrationLevel selected by the user (which is another select tag).

  authenticationProtocols: computed('model.integrationLevel', function() {
    const integrationLevel = this.get('model.integrationLevel');
    if (integrationLevel) {
      debugger;
      const protocols = integrationLevel.get('authenticationProtocols');
      set(this, 'model.authenticationProtocol', get(protocols, 'firstObject')); <--------- problem line
      return protocols;
    } else {
      return [];
    }
  }),

This works fine for creating a new record as nothing was previously selected. When editing a record (recycling the component) the authenticationProtocol gets set back the the first element in the dropdown regardless of what as previously selected. I understand why and have marked the culprit.

This is a pretty common scenario - (the contents of on list are dependent on the selection of another list). What is the recommended was to handle this sort of scenario? Is there something neat in ember that can handle this nicely?




Aucun commentaire:

Enregistrer un commentaire