Better LinkedValueMixin Warning
Input elements of type `checkbox`, `hidden`, or `radio` can have a `value` without `onChange`. Also, if the input is `disabled`, who cares that it doesn't have an `onChange`?
Tim Yung committed
Jan 10, 2014 at 20:13 UTC
bcacd17f8b6561c7f21fcbbb6a507b5c2459af96
1 file changed
+12
-2
src/dom/components/LinkedValueMixin.js
+12
-2
@@ -21,6 +21,12 @@
21
22
var invariant = require('invariant');
23
24
+var hasReadOnlyValue = {
25
+ 'checked': true,
26
+ 'hidden': true,
27
+ 'radio': true
28
+};
29
+
30
/**
31
* Provide a linked `value` attribute for controlled forms. You should not use
32
* this outside of the ReactDOM controlled form components.
@@ -29,12 +35,16 @@ var LinkedValueMixin = {
35
propTypes: {
36
value: function(props, propName, componentName) {
37
if (__DEV__) {
32
- if (props[propName] && !props.onChange && !props.readOnly) {
38
+ if (props[propName] &&
39
+ !hasReadOnlyValue[props.type] &&
40
+ !props.onChange &&
41
+ !props.readOnly &&
42
+ !props.disabled) {
43
console.warn(
44
'You provided a `value` prop to a form field without an ' +
45
'`onChange` handler. This will render a read-only field. If ' +
46
'the field should be mutable use `defaultValue`. Otherwise, set ' +
37
- 'either `onChange` or `readOnly`. '
47
+ 'either `onChange` or `readOnly`.'
48
);
49
}
50
}