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
Bug: value={this.state.gender} does not reflect gender from onValueChange #151
Comments
can you reproduce this on snack.expo.io? |
here is the link I can reproduce it, the field is showing Male, not M: |
maybe i'm not understanding. you're setting the |
I want the value shown in the field is M, and also the gender in the state is M, they should be the same, right now they are not the same, it is shown in the field as Male, but the this.state.gender is actually M, I want the shown value reflect the actual state.gender. |
you need to set the |
The label and the value have to be the same? it should not, the gender value is set to M by calling setState, but it shows as Male, you think that is not a bug? |
@idoor88 did you ever resolve this? I have a list of currencies for example: In the picker I show the label which is correct, however when I select the label in the picker I then want it to display the actual value (GBP / USD... NOT Great British Pound). In the docs under Value it says:
Not sure about the above since my value & label are both different? It should display the Value in the input and not the label text, or am I missing something? |
@idoor88 & @lfkwtz further to my above comment I made a change in react-native-picker-select index.js which will resolve the issue. (If it is an issue?) line 358 which renders the TextInput: Hope this helps some people. |
The value will never be displayed to the end user. Whatever you want the end user to see belongs in the label field. |
@lfkwtz What if I want to display the value in the input when it's selected, but the label in the picker box when expanded? I have a dropdown of country net numbers. I want the selected net number to be visible for users, but I want the options list also to contain the label (ie country name) visible in the input visible when expanded |
definitely possible using headless mode |
@lfkwtz thanks! I see this |
headless is available on ios too
if you come up with a nice example of what you're working on feel free to share it and i'll add it to the main snack examples |
In following case, when Male or Female selected, the value passed in onValueChange is M or F, and it is set to state correctly by this.setState({gender:value}); but the value={this.state.gender} shows Male or Female, not M or F:
const placeholder = {
label: 'Select a gender...',
value: null,
color: '#9EA0A4',
};
const genders = [
{
id: 1,
label: 'Male',
value: 'M',
},
{
id: 2,
label: 'Female',
value: 'F',
},
];
<RNPickerSelect
placeholder={placeholder}
items={genders}
onValueChange={(value) => {
console.log("valueChange value: ", value);
this.setState({
gender: value,
});
}}
style={pickerSelectStyles}
value={this.state.gender}
useNativeAndroidPickerStyle={false}
ref={(ref) => this.genderRef = ref}
/>
Steps to reproduce the behavior:
Expected behavior
The field should show M instead of Male
Smartphone (please complete the following information):
The text was updated successfully, but these errors were encountered: