Skip to content

Commit

Permalink
fix: clear input on choices update
Browse files Browse the repository at this point in the history
  • Loading branch information
TymekDev committed Mar 26, 2024
1 parent 4207467 commit dd0e434
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions inst/www/shiny-semantic-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,15 @@ $.extend(semanticDropdownBinding, {
},

receiveMessage: function(el, data) {
let value = data.value;
if (data.hasOwnProperty('choices')) {
// setup menu changes dropdown options without triggering onChange event
$(el).dropdown('setup menu', data.choices);
// when no value passed, return null for multiple dropdown and first value for single one
if (!data.hasOwnProperty('value')) {
let value = ""
if (!$(el).hasClass('multiple')) {
value = data.choices.values[0].value
}
this.setValue(el, value);
}
// either keep the value provided or use the fact that an empty string clears the input and triggers a change event
value ||= ""
}

if (data.hasOwnProperty('value')) {
this.setValue(el, data.value);
}
this.setValue(el, value);

if (data.hasOwnProperty('label')) {
$("label[for='" + el.id + "'").html(data.label);
Expand Down

0 comments on commit dd0e434

Please sign in to comment.