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.

getSelectedValues only return previous clicked values

See original GitHub issue

Expected Behavior

https://materializecss.com/select.html Say we have 3 options as described in the above link. Here are my actions and return value

# Click Option clicked Expected value return from instance.getSelectedValues() return from e.target.value
1 Option 1 Option 1 `` Option 1
2 Option 2 Option 2 Option 1 Option 2
3 Option 3 Option 3 Option 2 Option 3
4 Option 1 Option 1 Option 3 Option 1

When instance.getSelectedValues() is called, it always return previous clicked values.

It should return the current clicked value

Current Behavior

See the return from column 4

Steps to Reproduce (for bugs)

Add the below code to the select onChange

        console.log(instance.getSelectedValues());
        console.log(e.target.value);

Context

Your Environment

  • Version used: v1.0.0
  • Browser Name and version: Chrome
  • Operating System and version (desktop or mobile): Mac desktop

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
earwole1commented, Jun 5, 2020

This is still an issue for me on Firefox as well. And as @weasteam mentioned, multiple seems to work but obviously defeats the purpose when multiple isn’t wanted.

It appears that _setSelectedState() is not being called at the appropriate time.

For instance, if you call instance._setSelectedState() before instance.getSelectedValues(), then the correct value is returned as expected.

1reaction
earwole1commented, Jul 29, 2020

Same problem still. Is there any workaround to get it working without using multiple? I guess I could parse the values generated by the instance in options to get the originals (the ones I set), but it doesn’t seem clean.

See above: if you call instance._setSelectedState() before instance.getSelectedValues() then the correct value is returned, even when not using multiple.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java jList1.getSelectedValue() returns an Object. I need a ...
Method getSelectedValue() from class JList returns selected object which you've added in ListModel . Either it can be a String,Integer or ...
Read more >
JList (Java Platform SE 7 ) - Oracle Help Center
Returns the value for the smallest selected cell index; the selected value when only a single item is selected in the list. Object[],...
Read more >
get selected values of Picklist (Multi-Select) as list of string
I'm trying to get selected values and labels of picklist (Multi-Select) for a ... I tried this and it is the same, return...
Read more >
Get selected values in a multi-select drop-down with JavaScript
We can select the multiple options in the dropdown list using the multiple attribute. There are several ways in JavaScript to return the...
Read more >
How to determine the items that are selected in a ListBox control
Microsoft provides programming examples for illustration only, ... The Selected property of a list box is an array of values where each value...
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