Input text in sweetAlert

sweet alert multiple inputs
sweetalert loading
sweet alert button color
sweet alert font-size
sweet alert jsfiddle
adminlte sweet alert

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:

    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:

  title: "An input!",
  text: "Write something interesting:",
  type: "input",
  showCancelButton: true,
  closeOnConfirm: false,
  animation: "slide-from-top",
  inputPlaceholder: "Write something"
  if (inputValue === false) return false;

  if (inputValue === "") {
    swal.showInputError("You need to write something!");
    return false

  swal("Nice!", "You wrote: " + inputValue, "success");

SweetAlert2, Note that we're using content: "input" in order to both show an input-field and retrieve its value when the user clicks the confirm button: swal({. text: 'Search for a​  Since SweetAlert is promise-based, it makes sense to pair it with AJAX functions that are also promise-based. Below is an example of using fetch to search for artists on the iTunes API. Note that we're using content: "input" in order to both show an input-field and retrieve its value when the user clicks the confirm button:


Give the input the autofocus tag.

text: '<br /><form method="post" id="taxcode-update" name="taxcodeUpdate">'
    + '<input id="admin-tax-code" autofocus minlength="3" class="form-control wedding-input-text wizard-input-pad" type="text" name="taxCode" placeholder="Codice fiscale">'
    + '</form>',

Changing the Overlay background color of sweet alert 2, It can either be added as a configuration under the key text (as in the example custom content, beyond just text and icons. Examples: swal({. content: "input",. }  input type checkbox in html text not working. Ask Question Asked 3 years, 8 months ago. Input text in sweetAlert. 0. multiple types of input with Sweetaleart2. 0.

The variable used is 'name'

 const {value: name} = await swal({
  title: 'Input your name',
  input: 'text',
  inputPlaceholder: 'Enter here'

if (name) {
  swal('Entered name: ' + name)

$('button'). click(function(){ swal({ title: 'Enter email address', input: 'email' }). then(function (email) { swal({ type: 'success', html: 'Your email: ' + email. It looks like you can use a Sweet Alert with a type of 'input' (as opposed to 'error' or 'warning'). $window.swal({title: 'Text Entry', text: 'Put some text here, please.', type: 'input'}); From the Github README:A prompt modal where the user's input is logged:

Use Sweetalert2. There are numerous examples for input prompts to be found here, all of them using modern async/await constructs. If you want it the old way, try this:{
    title: "An input!",
    text: "Write something interesting:",
    input: 'text',
    showCancelButton: true        
}).then((result) => {
    if (result.value) {
        console.log("Result: " + result.value);

('Any fool can use a computer') A title with a text under. My alerts have been rendering with a random fieldset in the html, I am not using type "input" for any of these. sweetAlert({ type: 'success' title: 'Report Archived' text: 'Report has been archived."

Just test this

   title: 'Cool example',
   text: 'Any text that you consider useful for the form',
   showCancelButton: true,
   confirmButtonColor: '#DD6B55',
   confirmButtonText: 'Get form data!',
   closeOnConfirm: true,
   formFields: [
       { id: 'name', placeholder:'Name Field' },
       { id: 'nickname', placeholder:'Add a cool nickname' }
   ], function(isConfirm) {
   // do whatever you want with the form data
   console.log(this.swalForm); // { name: 'user name', nickname: 'what the user sends' }

How do I change the background color on sweet alert? Get the state of the current SweetAlert modal. swal.getState() setActionValue: 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. swal.setActionValue({ confirm: 'Text from input' }) stopLoading: Removes all loading states on the modal's buttons.

the overlay and apply the css using jqueries . css() function. If the input type is checkbox, inputValue will represent the checked state. If the input type is text, email, number, tel or textarea a Promise can be accepted as inputValue. inputOptions {} If input parameter is set to "select" or "radio", you can provide options. Can be a Map or a plain object, with keys that represent option values and

on pop up of swal. is there any method to prefill them, e.g. for editing a text. Sweet Alert can also receive user input text. Just set the content to “input”. Again, you can get the input value submitted from Promise resolved value{ title: "An input!", text: "Write something interesting:", input: 'text', showCancelButton: true }).then((result) => {() That's not directly supported by SweetAlert (because we keep things simple), but you can do it by writing the HTML yourself. From the documentation : Multiple inputs aren't supported, you can achieve them by using html and preConfirm parameters.

  • Because you are using an older version of sweet alert. I was having the same and get resolved by updating the sweet alert library from here.
  • This solution will work only the first time you call the modal, take a look on this modification I made to demonstrate that any ideas?
  • I don't know, sorry! Although the newest version of Sweet Alert allows a type:input, which may work better? @DomingoSL