Skip to content

Commit

Permalink
Merge pull request #41 from mplacekCS/feat/AddedOnErrorEvent
Browse files Browse the repository at this point in the history
Added onError event handling
  • Loading branch information
mprzodala authored Sep 6, 2017
2 parents 68448e7 + fb203db commit c29cbb8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class Form extends React.Component {
runSubmit(errors, modelData) {
const model = cloneObject(modelData);
if (Object.keys(errors).length > 0) {
if (this.eventsListener) this.eventsListener.callEvent('error', errors);
if (this.props.onError) this.props.onError(errors, model);
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/FormEventsListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class FormEventsListener {
validate: [],
changeModel: [],
reset: [],
error: [],
};
}
registerEvent(name) {
Expand Down
2 changes: 1 addition & 1 deletion tests/FormEventsListener.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('FormEventsListener', () => {

it('should not unregister event if not exists', () => {
eventsListener.unregisterEvent('afterSubmit');
expect(Object.keys(eventsListener.eventsListeners).length).toBe(4);
expect(Object.keys(eventsListener.eventsListeners).length).toBe(5);
});

it('should register event listener', () => {
Expand Down

0 comments on commit c29cbb8

Please sign in to comment.