Input text in sweetAlert

DomingoSL picture DomingoSL · Apr 28, 2015 · Viewed 76k times · Source

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/

Answer

Jai Kumar Rajput picture Jai Kumar Rajput · Nov 6, 2015
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");
});