ember-cli-materialize icon indicating copy to clipboard operation
ember-cli-materialize copied to clipboard

selectable-item-group picks wrong label source if optionValuePath == 'content'

Open LexLythius opened this issue 9 years ago • 0 comments

I need a selectable group item to yield object values (not just ids), which works fine with {{view 'select'}}. However, with selectable-item-group derivatives, label is messed up.

Say we have

var content = [
  { id: 1, name: "one" },
  { id: 2, name: "two" },
];

with

{{md-checks
  optionValuePath='content'
  labelValuePath='content.name'
}}

Problem is the following code:

    _labelPath:optionLabelPath.replace(/^content\.?/, '');

[...]

      if (valuePath && labelPath) {
        return Ember.A(
          content.map(el => {
            return {value: get(el, valuePath), label: get(el, labelPath)};
          })
        );
      } else {
        return Ember.A(
          content.map(el => {
            return {value: el, label: el};
          })
        );
      }

Path prefix 'content' is stripped from both property paths, so the if fails.

Solution would be simply removing the if and letting Ember.get do the right thing, since Ember.get(obj, "") === obj:

    return Ember.A(
      content.map(el => {
        return {value: get(el, valuePath), label: get(el, labelPath)};
      })
    );

That does the trick for me. I can't get ember test to run well right at this time, however (some dependency issue) so I don't have a PR.

LexLythius avatar Aug 20 '15 21:08 LexLythius