TransWikia.com

How to add function to onChange in Input cmponent?

Stack Overflow Asked by Will Black on December 23, 2021

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?

2 Answers

yes you can call multiple functions this way

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

Answered by a.ak on December 23, 2021

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();
};

Answered by Hend El-Sahli on December 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP