question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

preConfirm with inputValidator

See original GitHub issue

Is it possible to use inputValidator with preConfirm? Looking at source code, it looks like inputValidator only runs if there’s input fields inserted using the default method but not if I’m inserting them using preConfirm.

I suppose it would be nice to have a postConfirm in this case?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
gvernicommented, Feb 5, 2019

The inputValidator is not called. I think it’d be good that this function gets called so the user can validate custom html aswell instead of having to use preConfirm.

As explained originally, the inputValidator is only used when the input is defined through the input property of swal. And it couldn’t be otherwise: if the input to the swal is defined through html, then swal doesn’t know which of the element(s) is to be considered an input.

So even though the user input could be wrong, the last then block gets called, which is not what I want since input is invalid:

The only (and the correct) way to stop the swal promise to resolve (i.e. to execute the then block), is to use the showValidationError(). So this is the expected behavior. Please also note that this latter is deprecated and you should use showValidationMessage() instead.

Does it answers your doubts?

1reaction
limontecommented, Aug 11, 2016

Aha, sorry. The answer for your question is: inputValidator is working for swal2 input fields only (input parameter).

Inputs in the html parameter are totally custom and inputValidator can’t do magic and validate whatever you provides in custom HTML code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use sweetalert2 preConfirm with httpRequest which ...
I have an Angular form component which sends a http request and subscribes to that request. ... For some reason, my swal.preConfirm doesn't...
Read more >
Validation Message with a Custom Icon - SweetAlert2 example
Swal.fire({ title: 'Enter your name', input: 'text', customClass: { validationMessage: 'my-validation-message' }, preConfirm: (value) => { if (!value) ...
Read more >
View Raw - UNPKG
(modalElement: HTMLElement) => void; /** * Determines whether given `inputValidator` and `preConfirm` functions should be expected to to signal * validation ...
Read more >
sweetalert - Informática Instrumental - 9 - Passei Direto
inputValidator : sweetAlert. ... inputValidator === null) { var _inputValidator = function _inputValidator(url) { return new ... preConfirm) { sweetAlert.
Read more >
SweetAlert2 - Translider Demenagement
Use it in combination with the preConfirm parameter. ... inputValidator, null, Validator for input field, should return Promise, see usage example.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found