Skip to content

Commit d23069d

Browse files
committed
Release 0.16.8
1 parent f2975d9 commit d23069d

File tree

7 files changed

+23
-33
lines changed

7 files changed

+23
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-form-controlled",
3-
"version": "0.16.7",
3+
"version": "0.16.8",
44
"description": "React controlled form components. The main idea is to make forms as simple as possible.",
55
"author": {
66
"name": "Zlatko Fedor",

src/Element.jsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,6 @@ export default class Element extends Component {
6767
return this.state.value;
6868
}
6969

70-
getOriginalValue() {
71-
const parent = this.getParent();
72-
const { originalValue, valueIndex } = this.props;
73-
74-
if (valueIndex) {
75-
return parent.props.index;
76-
}
77-
78-
return originalValue;
79-
}
80-
8170
setValue(value, component = this) {
8271
//this.clearTimeout();
8372
this.setState({ value });

src/Fieldset.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,13 @@ export default class Fieldset extends Element {
259259
}*/
260260

261261
if (child.type && child.type.isElement) {
262-
const { name, value: originalValue } = child.props;
262+
const { name, value: childValue, valueIndex } = child.props;
263263

264264
this.disableSmartUpdate(name);
265265

266266
return cloneElement(child, {
267267
parent: this,
268-
originalValue,
268+
originalValue: valueIndex ? this.props.index : childValue,
269269
value: this.getChildValue(name),
270270
});
271271
}

src/FieldsetIndex.jsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ import React, { PropTypes } from 'react';
22
import Element from './Element';
33

44
export default class FieldsetIndex extends Element {
5-
static contextTypes = {
6-
...Element.contextTypes,
7-
};
8-
9-
static isElement = Element.isElement;
10-
115
static propTypes = {
126
...Element.propTypes,
137
format: PropTypes.func,
@@ -17,6 +11,22 @@ export default class FieldsetIndex extends Element {
1711
name: '.',
1812
};
1913

14+
shouldComponentUpdate(nextProps, nextState) {
15+
const { props } = this;
16+
17+
const oldFormat = props.format;
18+
const oldIndex = props.parent.props.index;
19+
20+
const newFormat = nextProps.format;
21+
const newIndex = nextProps.parent.props.index;
22+
23+
if (oldFormat(oldIndex) !== newFormat(newIndex)) {
24+
return true;
25+
}
26+
27+
return super.shouldComponentUpdate(nextProps, nextState);
28+
}
29+
2030
render() {
2131
const parent = this.getParent();
2232
const index = parent.props.index;

src/Form.jsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,8 @@ function errorToProperty(err) {
1919
}
2020

2121
export default class Form extends Fieldset {
22-
static isElement = Fieldset.isElement;
2322
static isForm = true;
2423

25-
static childContextTypes = {
26-
...Fieldset.childContextTypes,
27-
};
28-
29-
static contextTypes = {
30-
parent: PropTypes.object,
31-
};
32-
3324
static propTypes = {
3425
onChange: PropTypes.func.isRequired,
3526
onSubmit: PropTypes.func.isRequired,

src/Input.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default class Input extends Element {
3232
if (target.type === 'checkbox') {
3333
value = !!target.checked;
3434
} else if (target.type === 'radio' && target.checked) {
35-
value = this.getOriginalValue();
35+
value = this.props.originalValue;
3636
} else if (target.type === 'number') {
3737
const fixedValue = value
3838
.replace(',', '.')
@@ -55,9 +55,9 @@ export default class Input extends Element {
5555

5656
render() {
5757
const value = this.getValue();
58-
const { type, path } = this.props;
58+
const { type, path, originalValue } = this.props;
5959
const checked = (type === 'checkbox' && value)
60-
|| (type === 'radio' && value === this.getOriginalValue());
60+
|| (type === 'radio' && value === originalValue);
6161

6262
return (
6363
<input

src/utils/shallowCompare.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function shallowEqual(objA, objB, ignore = []) {
3939
// Test for A's keys different from B.
4040
for (let i = 0; i < keysA.length; i++) {
4141
const propName = keysA[i];
42-
if (ignore.indexOf(propName) !== -1) {
42+
if (ignore.indexOf(propName) !== -1 || typeof objA[propName] === 'function') {
4343
continue;
4444
}
4545

0 commit comments

Comments
 (0)