question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Dropdown] Can't get values after invoke $.dropdown('set values', values)

See original GitHub issue

When 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:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
azarisaeedcommented, Feb 7, 2020

I fixed it by add the same list to my select options too

for (var i = 0; i < response.length; i++) {
      var item = response[i];
      inner = inner + "<option value='" + item.value + "'>" + item.name + "</option>";
}
0reactions
wrycucommented, Dec 8, 2019

This is still an issue.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found