Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use options with key of arrays. #95

Open
jhon312020 opened this issue Oct 24, 2017 · 4 comments
Open

How to use options with key of arrays. #95

jhon312020 opened this issue Oct 24, 2017 · 4 comments

Comments

@jhon312020
Copy link

As per your example
const options = [
'Option 1',
'Option 2'
];

const options = [
{id:1, answer: 'Option 1'},
{id: 2, answer: 'Option 2'}
];
In this case I get selected value as false in renderOption. How to get selected value for the above set of options.

@jhon312020 jhon312020 changed the title How to use options with keys of arrays. How to use options with key of arrays. Oct 24, 2017
@irmela
Copy link

irmela commented Nov 14, 2017

I have the same problem as I need to pass key value pairs to options.

@jhon312020
Copy link
Author

You can use this function
function checkEqual(selectedOption, currentOption) {
if (selectedOption.id == currentOption.id)
return true;
}
In the render portion you can call the function with the parameter testOptionEqual
<RadioButtons
options={ options }
onSelection={ setSelectedOption.bind(this) }
selectedOption={this.state.selectedOption }
renderOption={ renderOption }
renderContainer={ renderContainer }
testOptionEqual = { checkEqual }
/>
This is how I made it to work.

@giantss
Copy link

giantss commented Apr 4, 2018

@ArnaudRinquin I am curious why can't I accept array objects like this

const options = [
          {
              label: 'Option 1',
              value: 'opt1'
          },
          {
              label: 'Option 2',
              value: 'opt2'
          },
          {
              label: 'Option 3',
              value: 'opt3'
          },
          {
              label: 'Option 4',
              value: 'opt4'
          },
          {
              label: 'Option 5',
              value: 'opt5'
          },
          {
              label: 'Option 6',
              value: 'opt6'
          }
      ];

@motogod
Copy link

motogod commented Jun 14, 2018

@giantss If you want to pass an array of objects, you have to add this code extractText={ (option) => option.label } in your <SegmentedControls />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants