Skip to content

Commit

Permalink
Merge pull request #11161 from kamalaknn/bugfix_select_optgroup
Browse files Browse the repository at this point in the history
[BUGFIX BETA] Fix initial selection for select with optgroup
  • Loading branch information
mixonic committed May 15, 2015
2 parents 5b3b67e + f3a8792 commit 7b33514
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ember-htmlbars/lib/templates/select.hbs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#if view.prompt}}<option value="">{{view.prompt}}</option>{{/if}}{{#if view.optionGroupPath}}{{#each view.groupedContent as |group|}}{{view view.groupView content=group.content label=group.label selection=view.selection multiple=view.multiple optionLabelPath=view.optionLabelPath optionValuePath=view.optionValuePath optionView=view.optionView}}{{/each}}{{else}}{{#each view.content as |item|}}{{view view.optionView content=item selection=view.selection parentValue=view.value multiple=view.multiple optionLabelPath=view.optionLabelPath optionValuePath=view.optionValuePath}}{{/each}}{{/if}}
{{#if view.prompt}}<option value="">{{view.prompt}}</option>{{/if}}{{#if view.optionGroupPath}}{{#each view.groupedContent as |group|}}{{view view.groupView content=group.content label=group.label selection=view.selection value=view.value multiple=view.multiple optionLabelPath=view.optionLabelPath optionValuePath=view.optionValuePath optionView=view.optionView}}{{/each}}{{else}}{{#each view.content as |item|}}{{view view.optionView content=item selection=view.selection parentValue=view.value multiple=view.multiple optionLabelPath=view.optionLabelPath optionValuePath=view.optionValuePath}}{{/each}}{{/if}}
19 changes: 19 additions & 0 deletions packages/ember-views/tests/views/select_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,25 @@ QUnit.test("select with group doesn't break options", function() {
deepEqual(select.get('selection'), content.get('firstObject'));
});

QUnit.test("select with group works for initial value", function() {
var content = Ember.A([
{ id: 1, firstName: 'Yehuda', organization: 'Tilde' },
{ id: 2, firstName: 'Tom', organization: 'Tilde' },
{ id: 3, firstName: 'Keith', organization: 'Envato' }
]);

run(function() {
select.set('content', content);
select.set('optionGroupPath', 'organization');
select.set('optionValuePath', 'content.id');
select.set('value', 2);
});

append();

equal(select.$().val(), 2, "Initial value is set properly");
});

QUnit.test("select with group observes its content", function() {
var wycats = { firstName: 'Yehuda', organization: 'Tilde' };
var content = Ember.A([
Expand Down

0 comments on commit 7b33514

Please sign in to comment.