简体   繁体   中英

Get the value from input of Formik's Field

There is a Formik field for validating some data, it looks like this:

<Formik
    initialValues={initialValues}
    validationSchema={validationSchema}
    onSubmit={values => this.handleDelete(values)}>
    {({ values, errors, touched, setFieldValue }) => (
      <Form>
        <Field
          className="add-input"
          name="deleteText"
          as={Input}
          placeholder="Write DELETE"
        />
      </Form>
    )}
 </Formik>

If I write a text, "abc" in the input, with DevTools in Inspect mode this looks like this:

<form action ="#">
  <div class="ui input add-input">
     <input name="deleteText" placeholder="Write DELETE" type="text" value="abc">
  </div>
</form>

Here it can be seen the introduced text, but how can I access it that text from the code?

  1. You can use values[<name>] like values['deleteText'] for your code (inside the render function of the Formik)

or

  1. You can pass onChange prop to the <Field>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM