Will Black
Will Black

Reputation: 402

How to add function to onChange in Input cmponent?

I got form (use formik + andt). Can't find how to add function when Input changes. for example my mail field:

<Form.Item
  help={fieldHelp()}
  validateStatus={fieldValidateStatus('email')}
  label="E-mail"
  name="email"
  >
  <Input
    value={values.email}
    onChange={handleChange} // how to add function here?
    onBlur={handleBlur}
   />
</Form.Item>

is it possible to add one more function to onChange={handleChange}? somethiing like this: onChange={handleChange, myfunction()} or another way?

Upvotes: 1

Views: 306

Answers (2)

Hend El-Sahli
Hend El-Sahli

Reputation: 6742

You 'll need to create a custom component for TextInput and manually pass error to it...

      <MyAppTextInput
        ...
        onChangeText={handleChange('latin')}
        onBlur={handleBlur('latin')}
        error={touched.latin && errors.latin}
      />
const onYourFieldChange = fieldName => {
  handleChange(fieldName);
  YourCustomFn();
};

Upvotes: 0

a.ak
a.ak

Reputation: 651

yes you can call multiple functions this way

onChange={(e) => {
    handleChange(e);
    myfunction()
}}

Upvotes: 1

Related Questions