galikvalkin / react-native-form-validation

Simple JS form validation
MIT License
17 stars 5 forks source link

add key as prop in FormItem #6

Closed wayoff closed 6 years ago

wayoff commented 6 years ago

add additional prop in FormItem, an optional one to identify which form item is being validated..

this is my case:


            <FormItem
              isRequired={true}
              validationFunction={emailValidation}
            >
              <TextInput 
                label="Email"
                type="stacked"
                backgroundColor="transparent"
                borderColor={this.state.isValid.email ? 'light' : 'danger'}
                color={this.state.isValid.email ? 'light' : 'danger'}
                keyboardType="email-address"
                value={this.state.email}
                onChangeText={this.onSetEmail.bind(this)}
              />
            </FormItem>

as you can see i'am checking if the email is valid via component state, problem is that i cannot identify what component is being validated as it's only giving me the props of TextInput

if possible something like this when submitted:

[{
   fieldToBeValidated: 'value' // default
   isValid: bool,
   key: 'email', // so we know which form item is being validated
   props: {},
   etc..
   etc..
}]
galikvalkin commented 6 years ago

@wayoff Hello and thank you for response;

For now:

validate method returns validation results for all fields that you've wrapped with FormItem component; And these results are in the same order, as you've rendered FormItems.

So:

submitResults[0] ---> FormItem №1 submitResults[1] ---> FormItem №2 submitResults[2] ---> FormItem №3

etc.