Browse Source

entry on controlled input with `value` null

main
Cheng Lou 11 years ago
committed by Connor McSheffrey
parent
commit
6b0353ddc9
  1. 20
      cookbook/cb-08-controlled-input-null-value tip.md
  2. 22
      cookbook/cb-08-controlled-input-null-value.md

20
cookbook/cb-08-controlled-input-null-value tip.md

@ -0,0 +1,20 @@
---
id: controlled-input-null-value-tip
title: Value of null for controlled input
layout: docs
permalink: controlled-input-null-value-tip.html
---
With a controlled input component, specifying a `value` prevents the user from changing the input unless you desire so (more info [here](forms.html)).
You might have ran into a problem where you specified a `value` but the input can still be changed. In this case, you might have accidentally set your `value` to `undefined` or `null`. The snippet below shows this phenomenon; after a second, the text be edited.
```js
/** @jsx React.DOM */
React.renderComponent(<input value="hi" />, mountNode);
setTimeout(function() {
React.renderComponent(<input value={null} />, mountNode);
}, 2000);
```

22
cookbook/cb-08-controlled-input-null-value.md

@ -0,0 +1,22 @@
---
id: controlled-input-null-value
title: Value of null for controlled input
layout: docs
permalink: controlled-input-null-value.html
---
### Problem
You specified a `value` parameter for your form input, but the input value can still be modified, contrary to [what you'd expect](forms.html).
### Solution
You might have accidentally set your `value` to `undefined` or `null`. The snippet below shows this phenomenon; after a second, the text be edited.
```js
/** @jsx React.DOM */
React.renderComponent(<input value="hi" />, mountNode);
setTimeout(function() {
React.renderComponent(<input value={null} />, mountNode);
}, 2000);
```
Loading…
Cancel
Save