[Dropdown] Can't get values after invoke $.dropdown('set values', values)
See original GitHub issueWhen a dropdrown values are changed by $('#dropdown').dropdown('set values', values)
and you call $('#dropdown').val()
does not return the selected value.
In my code I have two Dropwods one with some years and other that list months that are included in those years. When a years is selected months are updated with set values
but then I can’t get selected month. I order to deal with this issue I did this:
<div class='ui form'>
<div class='field'>
<label for="year">Year:</label>
<select name="year" class="ui dropdown" id="year">
<option value="2017" data-month="[1, 2, 3]">2016</option>
<option value="2017" data-month="[4, 5, 6]" selected>2017</option>
</select>
</div>
<div class="field">
<label for="month">Month:</label>
<select name="year" class="ui dropdown" id="month">
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
</div>
$(function (){
$('#year').dropdown({
onChange: function (value, text, $selectedItem) {
var arr = [];
var months = $('#year').find(':selected').data('month');
for (var i = 0; i < months.length; i++) {
var m = months[i];
arr.push({value: m, name: m});
}
arr[arr.length - 1].selected = true;
$('#month').dropdown('change values', arr);
}
});
$('#month').dropdown({
onChange: function (value, text, $selectedItem) {
$('#month').data('value', value); //To deal with issue
}
});
});
PS: I tried to make JSfiddle but didn’t work 😞 .
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Getting value of select (dropdown) before change
It works at first time you change the options, but if you stay on that select element, and press key "up" or "down"....
Read more >How to Handle Dropdown in Cypress | BrowserStack
Read guide on how to handle Dropdown in Cypress that would help in test ... Select – default value; Lowest to highest; Highest...
Read more >Get the Value/Text of Select or Dropdown on Change using JS
Use the value property to get the value of the element, e.g. select.value . Use the text property to get the text of...
Read more >How to get selected value in dropdown list using JavaScript
Method 1: Using the value property: The value of the selected element can be found by using the value property on the selected...
Read more >How to Capture the Value of Dropdown Lists with React ...
Adding the Dropdown Component ... Render them on the DOM inside App.js : 1.... 2 <DropdownButton 3 alignRight 4 title="Dropdown right" 5 id=" ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I fixed it by add the same list to my select options too
This is still an issue.