ReactNative - Tcomb-form-native: Enable/Disable user input programmatically

339 views Asked by At

I'm using tcomb-form-native for users to input their information. By default the library allows to input, but there are some cases in my application that users can input the text filed or other fields when some conditions are met

I cannot find any ways to make it come true.

Please give me some advice

1

There are 1 answers

0
Vishwaveer Raghuwanshi On

You can use onchange event of tcomb-form-native library

 <Form
        ref="loginForm"
        type={this.state.User}
        value={this.state.value}
        options={this.state.options}
        onChange={this.onChange}
      />

and in onchange you can update the fields based on the condition

onChange = data => {
//put your condition liek

if (data == 1) {
  var myOptions = t.update(this.state.options, {
    fields: {
      enddate: {
        disabled: { $set: false },
        minimumDate: {
          $set:
            data.startdate < data.enddate
              ? data.startdate
              : moment(new Date(data.startdate)).toDate()
        }
      }
    }
  });
}

};