Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds onValidation prop to GiftedForm #17

Merged
merged 1 commit into from
Feb 11, 2016

Conversation

danielweinmann
Copy link
Collaborator

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
Copy link
Owner

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
Copy link
Collaborator Author

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 added a commit that referenced this pull request Feb 11, 2016
Adds onValidation prop to GiftedForm
@FaridSafi FaridSafi merged commit 430696b into FaridSafi:master Feb 11, 2016
@FaridSafi
Copy link
Owner

Sure, I published 0.0.3

@peterknudsen
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants