I'm using a custom version of sweetalert to ask my user for an input
. I have managed to make the everything work but there is an strange behavior, In order to be able to input a text in the input box you have to click screen first:
swal({
title: "Aggiornamento profilo",
text: '<br /><form method="post" id="taxcode-update" name="taxcodeUpdate"><input id="admin-tax-code" minlength="3" class="form-control wedding-input-text wizard-input-pad" type="text" name="taxCode" placeholder="Codice fiscale"></form>',
type: "warning",
showCancelButton: false,
confirmButtonText: "Aggiorna il mio profilo",
closeOnConfirm: false
}, function () {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
});
Working example: https://jsfiddle.net/fvkppx06/
8 You can have inputs in the default SweetAlert type, as long as you set the html property to true. The issue is that unless the type is set to "input", SweetAlert adds a display: noneto input fields. It's a bit of a workaround, but you can change this in the js file from
Closes the currently open SweetAlert, as if you pressed the cancel button. Get the state of the current SweetAlert modal. Change the promised value of one of the modal's buttons. You can either pass in just a string (by default it changes the value of the confirm button), or an object.
Using promises. SweetAlert uses promises to keep track of how the user interacts with the alert. If the user clicks the confirm button, the promise resolves to true. If the alert is dismissed (by clicking outside of it), the promise resolves to null.
NPM combined with a tool like Browserify or Webpack is the recommended method of installing SweetAlert. Then, simply import it into your application: You can also find SweetAlert on unpkg and jsDelivr and use the global swal variable.
swal({
title: "An input!",
text: "Write something interesting:",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
animation: "slide-from-top",
inputPlaceholder: "Write something"
},
function(inputValue){
if (inputValue === null) return false;
if (inputValue === "") {
swal.showInputError("You need to write something!");
return false
}
swal("Nice!", "You wrote: " + inputValue, "success");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With