diff --git a/src/components/Form.jsx b/src/components/Form.jsx index 7aafcc6..b948117 100644 --- a/src/components/Form.jsx +++ b/src/components/Form.jsx @@ -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; } diff --git a/src/components/FormEventsListener.js b/src/components/FormEventsListener.js index 640e37e..c905ff5 100644 --- a/src/components/FormEventsListener.js +++ b/src/components/FormEventsListener.js @@ -5,6 +5,7 @@ class FormEventsListener { validate: [], changeModel: [], reset: [], + error: [], }; } registerEvent(name) { diff --git a/tests/FormEventsListener.test.js b/tests/FormEventsListener.test.js index c9c3ce7..c988324 100644 --- a/tests/FormEventsListener.test.js +++ b/tests/FormEventsListener.test.js @@ -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', () => {