3

I'm fairly new to javascript and I'm currently making a web client that display some data a database. Pretty standard stuff I guess. I use react.js and I installed react-widgets to get some nice widgets. The comboxbox I use is getting it's data from a mongo database depending on the collection chosen from another comboxbox. So by changing the collection, the data inside is updated to reflect the change. This works well, but I can't seem to be able to set the default value. Here the code to render the comboxbox:

<Combobox onChange= {this.handleOnChange} data = {this.state.myValues} defaultValue= {this.state.myValues[0]}/>

I have had this issue with a couple of widgets that does not seem to be able to get updated dynamically. They work if all the data is there the first time I'm rendering (static data for example), but they don't if the data is empty at first and gets populated afterward. *I did make sure I call setState to call the render function.

Did I miss something? Is it a javascript issue that I don't understand?

Thanks!

2 Answers 2

1

Try wrapping the Combobox with a condition.

Something like this

{ this.state.myValues[0] &&
  YOUR_TAG_COMBO
<Combobox onChange= {this.handleOnChange} data = {this.state.myValues} defaultValue= {this.state.myValues[0]}/>

}
Sign up to request clarification or add additional context in comments.

2 Comments

Could you please add some explanation to your answer, and format code according to the markdown?
Nice. I solved my problem with DropdownList: { data && <DropdownList defaultValue={ data.value } /> }
0

I think you might be better off using the value prop, instead of defaultValue, it will give you more control over the component, and it will repopulate the form element when the state has changed.

3 Comments

I'll try that. Is there a way to check for existing property inside a control. The thing I miss from language like C#, Java or C++ is that the api doc is very much non-existing for most of the widgets I use.
I'm not sure what you mean by "inside a control"?
Sorry for the late response, I've got sidetracked on other things. What I meant, was you need to go into the code and read it to know what's available... due to the lack of documentation. For example, to reset the selected value of a combobox or to force the selection of a value within the combobox one must do something like: this.refs["myComboBox"].state.value = forceSelectedValue;

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.