[英]how to getvalue of textarea in react?
I am using react-final-form
and TextareaAutosize
in my example .I am trying to get the value of text-area
but not able to do that.我在我的示例中使用react-final-form
和TextareaAutosize
。我试图获取text-area
的值,但无法做到这一点。 I am able to get value of input
field but not textarea
我可以获取input
字段的值,但不能获取textarea
here is my code https://codesandbox.io/s/react-final-form-simple-example-rd3rc这是我的代码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 API 链接https://final-form.org/docs/react-final-form/examples/simple
https://www.npmjs.com/package/react-textarea-autosize https://www.npmjs.com/package/react-textarea-autosize
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.我认为问题在于 TextAreaAutosize,因为它不知道如何将数据直接传递到您的表单。 So you might need to add a handler on that field for the onChange event.因此,您可能需要在该字段上为 onChange 事件添加处理程序。
Based on the final form documentation, this code sample below seems to work just fine: sandbox-code Just checkout the second attempt section.根据最终的表单文档,下面的这个代码示例似乎工作得很好: sandbox-code只需检查第二次尝试部分。
You can get value by this pop:你可以通过这个 pop 获得价值:
`onChange={(event) => { console.log(event.target.value) }}`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.