Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic defaultValue on Combobox React Widgets

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!

like image 604
ThePainnn Avatar asked Dec 06 '25 03:12

ThePainnn


1 Answers

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]}/>

}
like image 119
Name Avatar answered Dec 08 '25 17:12

Name