Need controlled Select component of React


Topic: Need controlled Select component of React

shilu911 pro asked 7 years ago

Hi there, I was wondering how could I pass values to Select component and make it a controlled component?

Mikołaj Smoleński staff answered 7 years ago

Hi, Please open our SelectPage which You can find in: docs/pages/pro/SelectPage.js It is a working example of controlled select component. You can change there everything You want. Regards

shilu911 pro commented 7 years ago

Hello Mikołaj, Thanks for your response, I checked the example, but I don't find a way to pass key-value pair to SelectOption, as well as a default checked attribute. What I want to do is to give a Select component a value when initialize the component. Thank you.

Mikołaj Smoleński staff commented 7 years ago

In the code below You can change option values by replacing "Option 1, Option 2...etc.": <SelectOption disabled>Choose your option</SelectOption> <SelectOption triggerOptionClick={this.optionClick}>Option nr 1</SelectOption> <SelectOption triggerOptionClick={this.optionClick}>Option nr 2</SelectOption> <SelectOption triggerOptionClick={this.optionClick}>Option nr 3</SelectOption> <SelectOption triggerOptionClick={this.optionClick}>Option nr 4</SelectOption> <SelectOption triggerOptionClick={this.optionClick}>Option nr 5</SelectOption> Example label Also You can change default values for selects in the following line: this.state = { value: "Choose your option", value2: "Choose your option", value3: "Choose your option", value4: "Choose your option", value5: "Choose your option" } For this moment, that is all we provide to control select. Regards

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Pro
  • Premium support: No
  • Technology: MDB React
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No