Skip to content

Commit

Permalink
Properly set the dropdown value when dealing with remote loaded choices
Browse files Browse the repository at this point in the history
This problem happens only when we have a dropdown created from a select
that loads remote content. In this scenario, we don't know in advance
which choices will be available, so we start with a select without any
options. When an choice is selected, module.set.value will try to set
the select value, but it will fail, since there's no options.

To fix this, module.set.value will add a new option to the select, before
setting the value. This will be done only if the dropdown input is a select
and if we are dealing with remote loaded content.
  • Loading branch information
davialexandre committed Jul 9, 2015
1 parent a99f26a commit 58b4046
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/definitions/modules/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2090,6 +2090,12 @@ $.fn.dropdown = function(parameters) {
return;
}
}

if($input.is('select') && settings.apiSettings) {
module.debug('Adding an option to the select before setting the value', value);
module.add.optionValue(value);
}

module.debug('Updating input value', value, currentValue);
$input
.val(value)
Expand Down

1 comment on commit 58b4046

@jlukic
Copy link
Member

@jlukic jlukic commented on 58b4046 Jul 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love when things are this easy to review

Please sign in to comment.