FaridSafi / react-native-gifted-form

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

Main: Moved Validation Errors Generation. GooglePlaces Widget: Exposed Request. ModalWidget: Implemented display title rather than value. #76

Closed sambwest closed 7 years ago

sambwest commented 8 years ago

Hi,

The issue: I don't want to use the submit widget to submit my forms, I want to use a button the navigation bar. (it could be any button). Putting the error generation as part of the SubmitWidget assumes too much about how I want to submit the form.

The module currently generates errors as part of the submit widget. I have extracted that functionality out and added it as a utility method as: GiftedFormManager.getValidationErrors.

This means in my navigation by I can use it as follows:


            action: () => {
              // get the validation results
              var validationResults = GiftedFormManager.validate(this._form.props.formName);

              // is the form valid?
              if(validationResults.isValid) {
                // get the values
                var values = GiftedFormManager.getValues(this._form.props.formName);
                // dispatch to add booking
                this.props.store.job.addBooking(values);
                // remove the scene
                Ugo.Actions.pop();
              }
              else {
                // get the errors
                var errors = GiftedFormManager.getValidationErrors(validationResults);

                // update the form's state with the errors
                this._form.setState({errors});
              }
            }

The change is transparent to the current SubmitWidget.