Skip to content

Commit d17e04c

Browse files
authored
Merge pull request davidkpiano#988 from kabbi/fix-intent-clearing-bug
Fixed reset intent clearing bug
2 parents a9b1e49 + d6b9cf6 commit d17e04c

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

src/components/control-component.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,18 @@ function createControlClass(s = defaultStrategy) {
403403
return;
404404
}
405405
case 'validate':
406+
if (containsEvent(validateOn, 'change')) {
407+
this.validate({ clearIntents: intent });
408+
}
409+
return;
406410
case 'reset':
407-
if (intent.type === 'reset') {
408-
this.setViewValue(modelValue);
409-
if (this.handleUpdate.cancel) {
410-
this.handleUpdate.cancel();
411-
}
411+
this.setViewValue(modelValue);
412+
if (this.handleUpdate.cancel) {
413+
this.handleUpdate.cancel();
412414
}
415+
dispatch(actions.clearIntents(model, intent));
413416
if (containsEvent(validateOn, 'change')) {
414-
this.validate({ clearIntents: intent });
417+
this.validate({});
415418
}
416419
return;
417420

test/control-component-spec.js

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,20 +1097,48 @@ Object.keys(testContexts).forEach((testKey) => {
10971097
test: modelReducer('test', initialState),
10981098
});
10991099

1100-
TestUtils.renderIntoDocument(
1101-
<Provider store={store}>
1102-
<Control.text
1103-
model="test.foo"
1104-
/>
1105-
</Provider>
1106-
);
1107-
11081100
it('should reset the control to the last loaded value', () => {
1101+
TestUtils.renderIntoDocument(
1102+
<Provider store={store}>
1103+
<Control.text
1104+
model="test.foo"
1105+
/>
1106+
</Provider>
1107+
);
1108+
11091109
store.dispatch(actions.load('test.foo', 'new foo'));
11101110
store.dispatch(actions.reset('test.foo'));
11111111

11121112
assert.equal(get(store.getState().test, 'foo'), 'new foo');
11131113
});
1114+
1115+
const onEvents = [
1116+
'change',
1117+
'focus',
1118+
'blur',
1119+
];
1120+
1121+
onEvents.forEach((updateOn) => {
1122+
onEvents.forEach((validateOn) => {
1123+
const condition = `updateOn="${updateOn}", validateOn="${validateOn}"`;
1124+
it(`should clear reset intent when ${condition}`, () => {
1125+
TestUtils.renderIntoDocument(
1126+
<Provider store={store}>
1127+
<Control.text
1128+
model="test.foo"
1129+
updateOn={updateOn}
1130+
validateOn={validateOn}
1131+
/>
1132+
</Provider>
1133+
);
1134+
1135+
store.dispatch(actions.reset('test.foo'));
1136+
const hasResetIntent = store.getState().testForm.foo.intents
1137+
.some(intent => intent.type === 'reset');
1138+
assert.equal(hasResetIntent, false, 'has no pending reset intents');
1139+
});
1140+
});
1141+
});
11141142
});
11151143

11161144
describe('deep initial value after reset', () => {

0 commit comments

Comments
 (0)