user944513
user944513

Reputation: 12729

how to getvalue of textarea in react?

I am using react-final-form and TextareaAutosizein my example .I am trying to get the value of text-area but not able to do that. I am able to get value of input field but not textarea

here is my code https://codesandbox.io/s/react-final-form-simple-example-rd3rc

 <div>
            <label>Text area Name</label>
            <Field
              component={TextareaAutosize}
              type="textarea"
              name="operatingPinCode"
              placeholder="Notes"
              label="About"
            />
          </div>

API link https://final-form.org/docs/react-final-form/examples/simple

https://www.npmjs.com/package/react-textarea-autosize

Upvotes: 1

Views: 3323

Answers (2)

hoang nguyen
hoang nguyen

Reputation: 11

You can get value by this pop:

    `onChange={(event) => {
        console.log(event.target.value)
    }}`

Upvotes: 0

Ionut Ardelean
Ionut Ardelean

Reputation: 507

Your final-form code is working fine. The problem I think lies with TextAreaAutosize, since it doesn't know how to pass data directly to your form. So you might need to add a handler on that field for the onChange event.

Based on the final form documentation, this code sample below seems to work just fine:sandbox-code Just checkout the second attempt section.

Upvotes: -1

Related Questions