gcanti / tcomb-form-native

Forms library for react-native
MIT License
3.15k stars 462 forks source link

Is it possible to programmatically collapse pickers? #231

Open pixelwhip opened 7 years ago

pixelwhip commented 7 years ago

I have a form with multiple enum inputs which create multiple collapsible iOS pickers. Each picker opens when the touchableOpacity is pressed and can be closed in the same manner. I'd like to have a picker collapse automatically when another picker is expanded but figure out how to do it. Is it possible to somehow trigger the collapse programmatically?

flamingo-peacock commented 7 years ago

I would love to know how to do this as well.

alvaromb commented 7 years ago

Hi!

I don't have time to implement it right now, but I would love to review a PR. Keep in mind that you should need to handle forms with several pickers.

ushafqat commented 7 years ago

I would absolutely love this too! The existing functionality is not very intuitive

chookg commented 7 years ago

期待这个功能!

mattfordham commented 6 years ago

Is this still not resolved or accounted for somewhere else? With a form containing multiple pickers, it's very odd to have them all remain open.

lukaszgoworko commented 6 years ago

with my PR you can now set your options like this (only iOS)

Options for form

  getCustomerOptions() {
    return {
      label: 'Customer',
      fields: {
        ...
        gender: {
          isCollapsed: this.state.genderIsCollapsed,
          nullOption: { value: '', text: 'Form of Address' },
          onCollapseChange: this.genderCollapseChange,
        },
        type: {
          isCollapsed: this.state.typeIsCollapsed,
        },
        ...
    }
  }

  ...

  genderCollapseChange(genderIsCollapsed) {
    const validationResult = this.createCustomerFormRef.pureValidate();
    this.setState({
      currentCustomer: validationResult.value,
      genderIsCollapsed,
    });
    if (newCollapse === false) {
      this.setState({
        typeIsCollapsed: true,
      });
    }
  }

  render() {
    return (
      ...
        <Formular
          ref={(c) => { this.createCustomerFormRef = c; }}
          type={Customer}
          value={this.state.currentCustomer}
          options={this.getCustomerOptions()}
        />
      ...

So you can set the collapse state for each Picker and react on collapse change from your component using the form. => you can collapse all other picker or open them or collapse only specific once.