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

Fixed reset intent clearing bug #988

Merged
merged 1 commit into from
Oct 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/components/control-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,18 @@ function createControlClass(s = defaultStrategy) {
return;
}
case 'validate':
if (containsEvent(validateOn, 'change')) {
this.validate({ clearIntents: intent });
}
return;
case 'reset':
if (intent.type === 'reset') {
this.setViewValue(modelValue);
if (this.handleUpdate.cancel) {
this.handleUpdate.cancel();
}
this.setViewValue(modelValue);
if (this.handleUpdate.cancel) {
this.handleUpdate.cancel();
}
dispatch(actions.clearIntents(model, intent));
if (containsEvent(validateOn, 'change')) {
this.validate({ clearIntents: intent });
this.validate({});
}
return;

Expand Down
44 changes: 36 additions & 8 deletions test/control-component-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1097,20 +1097,48 @@ Object.keys(testContexts).forEach((testKey) => {
test: modelReducer('test', initialState),
});

TestUtils.renderIntoDocument(
<Provider store={store}>
<Control.text
model="test.foo"
/>
</Provider>
);

it('should reset the control to the last loaded value', () => {
TestUtils.renderIntoDocument(
<Provider store={store}>
<Control.text
model="test.foo"
/>
</Provider>
);

store.dispatch(actions.load('test.foo', 'new foo'));
store.dispatch(actions.reset('test.foo'));

assert.equal(get(store.getState().test, 'foo'), 'new foo');
});

const onEvents = [
'change',
'focus',
'blur',
];

onEvents.forEach((updateOn) => {
onEvents.forEach((validateOn) => {
const condition = `updateOn="${updateOn}", validateOn="${validateOn}"`;
it(`should clear reset intent when ${condition}`, () => {
TestUtils.renderIntoDocument(
<Provider store={store}>
<Control.text
model="test.foo"
updateOn={updateOn}
validateOn={validateOn}
/>
</Provider>
);

store.dispatch(actions.reset('test.foo'));
const hasResetIntent = store.getState().testForm.foo.intents
.some(intent => intent.type === 'reset');
assert.equal(hasResetIntent, false, 'has no pending reset intents');
});
});
});
});

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