Skip to content

Commit dd0e434

Browse files
committed
fix: clear input on choices update
1 parent 4207467 commit dd0e434

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

inst/www/shiny-semantic-dropdown.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,15 @@ $.extend(semanticDropdownBinding, {
6363
},
6464

6565
receiveMessage: function(el, data) {
66+
let value = data.value;
6667
if (data.hasOwnProperty('choices')) {
6768
// setup menu changes dropdown options without triggering onChange event
6869
$(el).dropdown('setup menu', data.choices);
69-
// when no value passed, return null for multiple dropdown and first value for single one
70-
if (!data.hasOwnProperty('value')) {
71-
let value = ""
72-
if (!$(el).hasClass('multiple')) {
73-
value = data.choices.values[0].value
74-
}
75-
this.setValue(el, value);
76-
}
70+
// either keep the value provided or use the fact that an empty string clears the input and triggers a change event
71+
value ||= ""
7772
}
7873

79-
if (data.hasOwnProperty('value')) {
80-
this.setValue(el, data.value);
81-
}
74+
this.setValue(el, value);
8275

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

0 commit comments

Comments
 (0)