Tell us which versions you are using:
I am trying to assign a default Enum value in the Picker rendered by t.enums(). Basically for default I mean the value that the user has selected and saved previously - Please notice that the example below does not contain api calls, but in the real code the values are dinamically returned by APIs. Something like:
var Country = t.enums({
'IT': 'Italy',
'US': 'United States'
}, 'Country');
var myStruct = t.struct({
countries: Country,
});
var AwesomeProject = React.createClass({
getInitialState() {
return {
value: {
countries: {'UK' : 'United Kingdom'}
}
};
},
.....
<Form
ref="form"
type={myStruct}
value={this.state.value}
/>
.....
}
I have tried several different ways but with no success.
I have tried several ways to do that but none of them is working. Mainly I receive compile errors
Maybe that's the problem:
value: {
countries: {'UK' : 'United Kingdom'}
}
You are defining that countries has to be set to 'UK' default value, but your enum only expected one of the two provided ('IT' or 'US'). Can you try with one of these values?
@Moreno97 is right, it should be
{
countries: 'UK'
}
Hi Guys, it worked perfectly. Thank you both for the support!!
Most helpful comment
@Moreno97 is right, it should be