1

I have a dropdown I want to be pre-selected when the data is available. However there appears to be no real chance for that?

Since I am waiting for a change in state for a particular value using that value as the value= causes the selections to be unselectable, while using it as a defaultValue= causes the UI to not recognize the value unless a change to the element has been made meaning if the user decides to go with the default choice it wouldn't be passed up the to the API I am trying to pass it up to.

Is there a way to dynamically change a select box after the dom is ready after the components mounted and when a state is changed?

3
  • What are you waiting on? Can you use a promise? Commented Dec 3, 2015 at 22:50
  • have you tried using the default value in value and adding an onChange handler to allow it to be selected? Commented Dec 3, 2015 at 22:54
  • 1
    I have tried multiple ways of managing it, each one seems to have its own undesired effect. I've tried a combination of defaultVaule and value onChange up to and including trying all three at once with variant changes to see if one would work. As for what I am waiting on is the element exists on the DOM and based on interaction, or data generated up to that point I could possibly be waiting for an API response to populate the field with for the other selections at hand. I only know by that time what I want as a default Commented Dec 3, 2015 at 23:11

1 Answer 1

3

It's a bit difficult without seeing the code, but have you tried setting the value into the React component's state and rendering that instead? You can also read the state's value instead of the DropDown's.

getInitialState: function () {
        return {
          dropDownSelection: "some default value"
        };
      },

handleSelectionChanged: function (e) {
    this.setState({
      dropDownSelection: e.target.value
    });
  },

render: function () {
    return (
    //...
    <select className="form-control" value={this.state.dropDownSelection} onChange={this.handleSelectionChanged}>
    //...
    </select>
    );
}
Sign up to request clarification or add additional context in comments.

1 Comment

Any feedback @chris?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.