Skip to content

Commit 4e3723e

Browse files
Adds the @blur-context event, resolves wearebraid#304
1 parent d6982a1 commit 4e3723e

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

dist/formulate.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/formulate.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/formulate.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/libs/context.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ function blurHandler () {
503503
if (this.errorBehavior === 'blur' || this.errorBehavior === 'value') {
504504
this.behavioralErrorVisibility = true
505505
}
506+
this.$nextTick(() => this.$emit('blur-context', this.context))
506507
}
507508

508509
/**

test/cypress/support/commands.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Cypress.Commands.add('submittedValue', (name = 'inputUnderTest') => {
4747
// wait before executing, this allows us to prevent race conditions where
4848
// formSubmitted.finally() has not yet been called but we're already
4949
// re-running a submission test
50-
cy.wait(100)
50+
cy.wait(200)
5151
return window.getSubmittedValue()
5252
.then(value => cy.wrap(value[name]))
5353
})

test/unit/FormulateInput.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,4 +1107,24 @@ describe('FormulateInput', () => {
11071107
expect(wrapper.find('.formulate-input-element .custom-prefix').text()).toBe('Hello therejustin')
11081108
resetInstance()
11091109
})
1110+
1111+
it('emits a blur-context event on blur', async () => {
1112+
const listener = jest.fn();
1113+
const wrapper = mount(FormulateInput, {
1114+
propsData: {
1115+
type: 'text',
1116+
validation: 'required|email',
1117+
value: 'not an email',
1118+
errorBehavior: 'live'
1119+
},
1120+
listeners: {
1121+
'blur-context': listener
1122+
}
1123+
})
1124+
await flushPromises()
1125+
wrapper.find('input').trigger('blur')
1126+
await flushPromises()
1127+
expect(listener.mock.calls.length).toBe(1)
1128+
expect(listener.mock.calls[0][0].isValid).toBe(false)
1129+
})
11101130
})

0 commit comments

Comments
 (0)