mercredi 23 décembre 2015

Store index instead of name in Ember data from ember-paper select box

I'm using a select box component provided by ember-paper (http://ift.tt/1J5K20V).

This is how I've currently got it implemented:

{{#paper-select disabled=disableSelect model=model.fullnameIndex}}
  {{#each columnNames as |name index|}}
    {{#paper-option value=name}}
      {{name}}
    {{/paper-option}}
  {{/each}}
{{/paper-select}}

The columnNames array I'm using to populate the select box contains the following:

["Name", "Address", "City", "State", "Zip", "Email"]

When a selection is made from the select box, the value, in this case name (the first param of the each block), is passed to the fullnameIndex attribute on the model. But what I need to store on the model instead of name is the index (the second param of the each block).

Yes, I could store the index by setting that as the value on the #paper-option instead, but I don't want to do that for two reasons:

  1. When a user makes a selection from the select box, I don't want the value of the box to be a number, but rather show the name of the selection they chose - like how you'd expect a select box to function.
  2. This actually completely breaks anyways, because if you select the first option in the select box (whose index is 0), the select box doesn't show what you chose. It just continues to show the placeholder text.

Any help would be much appreciated. Thanks!




Aucun commentaire:

Enregistrer un commentaire