FaridSafi / react-native-gifted-form

📝 « One React-Native form component to rule them all »
MIT License
1.44k stars 214 forks source link

Adds onValidation prop to GiftedForm #17

Closed danielweinmann closed 8 years ago

danielweinmann commented 8 years ago

Now you can pass an onValidation prop to GiftedForm and it will run on every change of every widget.

If you don't pass it it does not validate, so we don't have worry about performance. Here is an example that solves @ScandyMark's #6:

export default class Form extends Component {
  constructor(props, context) {
    super(props, context)
    this.state = {
      isValid: false,
    }
  }

  handleValidation(validation) {
    if (this.state.isValid !== validation.isValid)
      this.setState({ isValid: validation.isValid })
  }

  render() {
    return (
      <GiftedForm
        formName="yourForm"
        validators={yourValidatorsHere}
        onValidation={this.handleValidation.bind(this)}
      >
        <GiftedForm.TextInputWidget name='fullName' />
        <GiftedForm.SubmitWidget
          title='Sign up'
          isDisabled={!this.state.isValid}
        />
      </GiftedForm>
    )
  }  
}
FaridSafi commented 8 years ago

Hello, thank you for your work Daniel, i'm currently traveling so I can not merge easily. I added you as collaborator, do you have a NPM account?

danielweinmann commented 8 years ago

Thanks! If you don't mind I'll still send PRs just for you to check the code before I merge it...is it ok with you?

Just created npm account: also danielweinmann ;)

FaridSafi commented 8 years ago

Sure, I published 0.0.3

peterknudsen commented 8 years ago

The onValidation doesn't work with SelectWidget. I have a validator on the SelectWidget itself, but the _validate method in WidgetMixin iterates over the individual OptionWidgets and doesn't fire because there are no validators on any of the options.