Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 8e8a375

Browse files
committed
onUpdate and onChange no longer called on form mount (previous bug). Fixes #907
1 parent 505d92e commit 8e8a375

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/components/form-component.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ function createFormClass(s = defaultStrategy) {
9191
}
9292

9393
componentDidMount() {
94-
this.handleUpdate();
95-
this.handleChange();
96-
9794
if (containsEvent(this.props.validateOn, 'change')) {
9895
this.validate(this.props, true);
9996
}

test/local-forms-spec.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,21 @@ describe('local forms', () => {
1111

1212
describe('standard usage with onUpdate', () => {
1313
let innerFormState;
14+
let dispatch;
1415

1516
const form = TestUtils.renderIntoDocument(
16-
<LocalForm onUpdate={(formValue) => innerFormState = formValue}>
17+
<LocalForm
18+
getDispatch={d => dispatch = d}
19+
onUpdate={(formValue) => innerFormState = formValue}
20+
>
1721
<Control.text model=".foo" />
1822
</LocalForm>
1923
);
2024

2125
const input = TestUtils.findRenderedDOMComponentWithTag(form, 'input');
2226

23-
it('should initially update with the loaded form value', () => {
27+
it('should update with the loaded form value', () => {
28+
dispatch(actions.setPristine('local'));
2429
assert.containSubset(innerFormState, {
2530
$form: {
2631
pristine: true,
@@ -45,36 +50,33 @@ describe('local forms', () => {
4550
});
4651

4752
describe('standard usage with onChange', () => {
48-
let innerModelState;
53+
let dispatch;
4954

5055
const form = TestUtils.renderIntoDocument(
51-
<LocalForm onChange={(modelValue) => innerModelState = modelValue}>
56+
<LocalForm getDispatch={d => dispatch = d}>
5257
<Control.text model=".foo" />
5358
</LocalForm>
5459
);
5560

5661
const input = TestUtils.findRenderedDOMComponentWithTag(form, 'input');
5762

5863
it('should initially have an empty object (by default) as the model value', () => {
59-
assert.deepEqual(innerModelState, {});
64+
assert.equal(input.value, ''); // { foo: '' }
6065
});
6166

6267
it('should behave like a normal form, with an internal Redux state', () => {
63-
input.value = 'changed';
64-
TestUtils.Simulate.change(input);
68+
dispatch(actions.change('local', { foo: 'changed' }));
6569

66-
assert.deepEqual(innerModelState, {
67-
foo: 'changed',
68-
});
70+
assert.equal(input.value, 'changed');
6971
});
7072
});
7173

7274
describe('onChange with initialState', () => {
73-
let innerModelState;
75+
let dispatch;
7476

7577
const form = TestUtils.renderIntoDocument(
7678
<LocalForm
77-
onChange={(modelValue) => innerModelState = modelValue}
79+
getDispatch={d => dispatch = d}
7880
initialState={{ foo: 'bar' }}
7981
>
8082
<Control.text model=".foo" />
@@ -84,16 +86,13 @@ describe('local forms', () => {
8486
const input = TestUtils.findRenderedDOMComponentWithTag(form, 'input');
8587

8688
it('should initially have an empty object (by default) as the model value', () => {
87-
assert.deepEqual(innerModelState, { foo: 'bar' });
89+
assert.equal(input.value, 'bar');
8890
});
8991

9092
it('should behave like a normal form, with an internal Redux state', () => {
91-
input.value = 'changed';
92-
TestUtils.Simulate.change(input);
93+
dispatch(actions.change('local', { foo: 'changed' }));
9394

94-
assert.deepEqual(innerModelState, {
95-
foo: 'changed',
96-
});
95+
assert.equal(input.value, 'changed');
9796
});
9897
});
9998

0 commit comments

Comments
 (0)