Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input text in sweetAlert

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/

like image 431
DomingoSL Avatar asked Apr 28 '15 13:04

DomingoSL


People also ask

Is it possible to have inputs in sweetalert?

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

How do I change the value of a sweetalert button?

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.

How do I use promises in sweetalert?

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.

How do I install sweetalert on my website?

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.


1 Answers

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");
});
like image 69
Jai Kumar Rajput Avatar answered Oct 11 '22 15:10

Jai Kumar Rajput