Skip to content

Commit

Permalink
fix: show the browser validation message for input (#2704)
Browse files Browse the repository at this point in the history
  • Loading branch information
limonte committed Feb 5, 2024
1 parent 7a007b9 commit 68d6d35
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions cypress/e2e/inputs.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ describe('Inputs', () => {
})
})

it('browser validation + browser validation message', (done) => {
SwalWithoutAnimation.fire({ input: 'text', inputAttributes: { pattern: '[0-9]+' } })

Swal.getInput().value = 'a'
Swal.clickConfirm()
setTimeout(() => {
expect(isVisible(Swal.getValidationMessage())).to.be.true
// Chrome: Please match the format requested.
// Firefox: Please match the requested format.
// Safari: Match the requested format.
expect(Swal.getValidationMessage().textContent.indexOf('atch the') !== -1).to.be.true
done()
}, TIMEOUT)
})

it('input email + built-in email validation', (done) => {
const invalidEmailAddress = 'blah-blah@zzz'
const validEmailAddress = '[email protected]'
Expand Down
2 changes: 1 addition & 1 deletion src/buttons-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const handleConfirmOrDenyWithInput = (instance, type) => {
handleInputValidator(instance, inputValue, type)
} else if (input && !input.checkValidity()) {
instance.enableButtons()
instance.showValidationMessage(innerParams.validationMessage)
instance.showValidationMessage(innerParams.validationMessage || input.validationMessage)
} else if (type === 'deny') {
deny(instance, inputValue)
} else {
Expand Down

0 comments on commit 68d6d35

Please sign in to comment.