Tcomb-form-native: Unable to assign default enum to Picker (t.enums)

Created on 30 Sep 2017  路  3Comments  路  Source: gcanti/tcomb-form-native

Version

Tell us which versions you are using:

  • tcomb-form-native v0.6.9
  • react-native v0.46.4

Expected behaviour

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.

Actual behaviour

I have tried several ways to do that but none of them is working. Mainly I receive compile errors

Steps to reproduce

  1. Create a Struct with an enum type of field
  2. Try to assign a default value to that field

Stack trace and console log


Most helpful comment

@Moreno97 is right, it should be

{
  countries: 'UK'
}

All 3 comments

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!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sibelius picture sibelius  路  4Comments

alexicum picture alexicum  路  6Comments

sibelius picture sibelius  路  5Comments

timdoes picture timdoes  路  4Comments

BogdanHossu picture BogdanHossu  路  6Comments