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 onChange

See original GitHub issue

is there a way to get more than just the value from the onChange event? I’d like to get other values from the objects defined in options.

eg:

` const options = [
      { key: 1, text: 'Green', value: ComponentGroup.GREEN, color: 'green' },
      { key: 2, text: 'Red', value: ComponentGroup.RED, color: 'red'},
      { key: 3, text: 'Blue', value: ComponentGroup.BLUE, color: 'blue'},
    ]

    return (
         <Dropdown className={styles.root} options={options} onChange={this.selectGroup} pointing='top left' icon={null} trigger={
            <span><span className={styles.groupIcon} style={{ backgroundColor: this.state.groupColor}} />Group</span>
         } />
    );
  }

  private readonly selectGroup = (event: React.SyntheticEvent<HTMLDivElement>, data: any) => {
     this.props.setGroup(data.value);
     this.setState({ groupColor: data.color });
  }`

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
levithomasoncommented, May 17, 2017

I would propose to keep your values unique. Consider also the reverse case, if there are several duplicate values, which one does the Dropdown select when used as a controlled component? There would be no way to know for sure.

2reactions
mihai-dinculescucommented, Apr 12, 2017

You shouldn’t worry too much about iterating though an array. It’s a fairly simple operation and a standard practice.

If you are keen on avoiding the iteration, you can have value store the index for each option.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dropdown using javascript onchange - Stack Overflow
I have a simple drop down and I want ...
Read more >
onchange Event - W3Schools
The onchange event occurs when the value of an element has been changed. ... The other difference is that the onchange event also...
Read more >
Get selected value of dropdown in JavaScript/jQuery on change
The idea is to bind the change event handler to the select box using the .change(handler) method. Now an alert is displayed whenever...
Read more >
JavaScript dropdown onchange - TAE - Tutorial
It is an event in JavaScript used to make the web pages dynamic. The onchange event gets triggered whenever the value of an...
Read more >
Get selected Text and Value of DropDownList in OnChange ...
The HTML Select DropDownList has been assigned a JavaScript OnChange event handler. When an item is selected in the HTML Select DropDownList, the ......
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