Skip to content

Commit

Permalink
Allow empty string for optionValuePath, causing whole object to be us…
Browse files Browse the repository at this point in the history
…ed as value.
  • Loading branch information
g-cassie committed Dec 16, 2015
1 parent 53f3430 commit 8d448e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
</option>
{{/if}}

{{optionValuePath}} / {{optionLabelPath}}

{{#each content key="@identity" as |item|}}
<option value="{{get item optionValuePath}}"
selected={{is-equal (get item optionValuePath) value}}>
<option value="{{if optionValuePath (get item optionValuePath) item}}"
selected={{is-equal (if optionValuePath (get item optionValuePath) item) value}}>
{{get item optionLabelPath}}
</option>
{{/each}}
13 changes: 13 additions & 0 deletions tests/integration/components/fm-select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@
assert.equal(this.$('option:last').attr('value'), 'goodbye');
});

test('entire object is set as value when optionValuePath is empty string', function(assert) {
const obj1 = Ember.Object.create({text: 'hi', itemValue: 'hello'});
const obj2 = Ember.Object.create({text: 'bye', itemValue: 'goodbye'});
this.set('content', Ember.A([obj1, obj2]));
this.set('optionLabelPath', 'text');
this.set('optionValuePath', '');
this.render(hbs `{{fm-select content=content optionLabelPath=optionLabelPath optionValuePath=optionValuePath}}`);
assert.equal(this.$('option:first').text().trim(), 'hi');
assert.equal(this.$('option:last').text().trim(), 'bye');
assert.equal(this.$('option:first').attr('value'), obj1.toString());
assert.equal(this.$('option:last').attr('value'), obj2.toString());
});

test('fm-select calls `action` with newly chosen value', function(assert) {
this.set('content', Ember.A([
{label: 'one', value: 1},
Expand Down

0 comments on commit 8d448e5

Please sign in to comment.