Tcomb-form-native: How to set border to select options

Created on 26 Jul 2017  路  4Comments  路  Source: gcanti/tcomb-form-native

I want to set the border in my selection option. I try to use this code but it does not work.

stylesheet.select.normal.borderWidth = 1;
stylesheet.select.error.borderWidth = 1;

So how can i do it please?

Most helpful comment

You can't. You have to use templates instead.

The original select from source code is:

return (
    <View style={formGroupStyle}>
      {label}
      <Picker
        accessibilityLabel={locals.label}
        ref="input"
        style={selectStyle}
        selectedValue={locals.value}
        onValueChange={locals.onChange}
        help={locals.help}
        enabled={locals.enabled}
        mode={locals.mode}
        prompt={locals.prompt}
        itemStyle={locals.itemStyle}
      >
        {options}
      </Picker>
      {help}
      {error}
    </View>
  );

Just copy/paste the files (android and ios) from tcomb-form-native/lib/templates/bootstrap to your project, then you can wrap the component with a <View> and style it.

To use your template, on your options definitions, just do:

formOptions: {
    yourSelectField: {
        template: require('..path/select') //react automatically choose the right OS version
    }
}

All 4 comments

You can't. You have to use templates instead.

The original select from source code is:

return (
    <View style={formGroupStyle}>
      {label}
      <Picker
        accessibilityLabel={locals.label}
        ref="input"
        style={selectStyle}
        selectedValue={locals.value}
        onValueChange={locals.onChange}
        help={locals.help}
        enabled={locals.enabled}
        mode={locals.mode}
        prompt={locals.prompt}
        itemStyle={locals.itemStyle}
      >
        {options}
      </Picker>
      {help}
      {error}
    </View>
  );

Just copy/paste the files (android and ios) from tcomb-form-native/lib/templates/bootstrap to your project, then you can wrap the component with a <View> and style it.

To use your template, on your options definitions, just do:

formOptions: {
    yourSelectField: {
        template: require('..path/select') //react automatically choose the right OS version
    }
}

Thanks @vendramini :+1: It's work for me

Thank you @vendramini it works perfectly fine. Here is an example.

  • Wrap the picker section in a view like this:
return (
    <View >
      {label}
      <View style={styles.selectStyle}>
      <Picker
        accessibilityLabel={locals.label}
        ref="input"
        style={selectStyle}
        selectedValue={locals.value}
        onValueChange={locals.onChange}
        help={locals.help}
        enabled={locals.enabled}
        mode={locals.mode}
        prompt={locals.prompt}
        itemStyle={locals.itemStyle}
      >
        {options}
      </Picker>
      </View>
      {help}
      {error}
    </View>
  );

an example of style can help other people out:
To get the same style as in iOS use this:

selectStyle: {
    borderWidth: 0.4,
    marginTop: 3,
    marginBottom: 5,
    height: 50,
    borderRadius: 4
  }

Hope that help.

How should I show the options? Where are you getting the option variable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

muthuraman007 picture muthuraman007  路  4Comments

casoetan picture casoetan  路  5Comments

BogdanHossu picture BogdanHossu  路  6Comments

flyingace picture flyingace  路  5Comments

abdelghafourzguindou picture abdelghafourzguindou  路  4Comments