FaridSafi / react-native-gifted-form

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

Validation (equalsTo & isPresent) #106

Open arberkryeziu opened 7 years ago

arberkryeziu commented 7 years ago

I would want to make a validation for 'Confirm Password' . Im not sure if I understand correctly the way validation is implemented here, but as Ive seen, I cant check on changing value e.g.

                                    passwordConfirm: {
                                        title: 'Password Confirm',
                                        validate: [{
                                            validator: 'equals',
                                            arguments: this.state.passValue,
                                            message: 'Password must be the same'
                                        }]
                                    },

where 'this.state.passValue' is the value of my password field stored through onChangeText. Does anyone have an idea how to implement this?

Is 'isPresent' the proper validator for SwitchWidget ? How can I validate on a switchedOn switcher ?

AuronChoo commented 6 years ago

Using custom validator like this :

                                 passwordConfirm: {
                                    title: 'Password Confirm',
                                    validate: [validator: (...args) => {
                                       if (args[0] === GiftedFormManager.getValue('signup_form', 'password')) {
                                         return true;
                                      } else {
                                         return false;
                                      }
                                   }],
                                   message: 'Password must be the same'
                                },