3

I can get the value just fine using:

this.refs.myTextArea.getDOMNode().value

Trying to set that does nothing.

rawbee
  • 2,946
  • 3
  • 18
  • 22
  • Can you add a jsFiddle that demonstrates the problem? http://stackoverflow.com/a/5589101/95190 – WiredPrairie May 27 '15 at 01:24
  • `this.refs.myTextArea.getDOMNode().value = ''` works for me. There must be something else interfering in your environment. – glortho May 27 '15 at 02:29
  • If `value` is set in your JSX, the component will be controlled even if you assign it an empty string. To give a default value and let it stay [uncontrolled](https://facebook.github.io/react/docs/forms.html#uncontrolled-components), use the `defaultValue` attribute instead of the standard `value`. – Ross Allen May 27 '15 at 04:49
  • @WiredPrairie I'm a jsFiddle n00b, but will try to set one up. – rawbee May 27 '15 at 15:38
  • @glortho definitely tried that in the onKeyPress handler, and it wasn't working. Will try to whittle it down to figure it out... – rawbee May 27 '15 at 15:38
  • @ssorallen it's definitely an uncontrolled component, i.e. no value set. Something else must be going on. – rawbee May 27 '15 at 15:39
  • @rawbee - fork this jsFiddle: https://jsfiddle.net/reactjs/69z2wepo/, which just provides the basic React to get you started. – WiredPrairie May 27 '15 at 17:08

3 Answers3

6

this.refs.myTextArea.getDOMNode().value = "";

goofballLogic
  • 37,883
  • 8
  • 44
  • 62
6

In even newer version of React ( > v15 ), you don't need findDOMNode(), this.refs.myTextArea.value ='' is enough

Vincent Taing
  • 3,283
  • 2
  • 18
  • 24
0

Is the value of your textarea being bind to a state of your component?

If yes then you can't set value like this, what you should do is call setState to change it.

Chenglu
  • 1,757
  • 2
  • 14
  • 23