t4t5 / sweetalert

A beautiful replacement for JavaScript's "alert"
https://sweetalert.js.org
MIT License
22.4k stars 2.84k forks source link

Getting value from multiple input? #788

Closed HadiAkmal closed 6 years ago

HadiAkmal commented 6 years ago

I'm using content with multiple input element:

msg.innerHTML = '<input type="text" name="FirstName" value="Abu"> <input type="text" name="LastName" value="Ali"> test <b>123<b>';

      content: msg,
      icon: 'info',
      buttons: ['Cancel', 'Save'],

Result: image

My question is, how do I retrieve the input value upon save?

Thanks in advance.

theevilhead commented 6 years ago

its a promise ... so after doing something like swal("Write something here:", { content: 'input', }) .then((value) => { swal('You typed: ${value}'); });

Know more about it here https://sweetalert.js.org/guides/#advanced-examples

HadiAkmal commented 6 years ago

@girishpatil

I can get the value if it's single input but I have 2 input field. When I tested it, the value output is true and I'm not getting the data that I keyin the 2 field.

GaboDot commented 6 years ago

I found example at "https://sweetalert2.github.io/"

const {value: formValues} = await swal({ title: 'Multiple inputs', html: '<input id="swal-input1" class="swal2-input">' + '<input id="swal-input2" class="swal2-input">', focusConfirm: false, preConfirm: () => { return [ $('#swal-input1').val(), $('#swal-input2').val()] } }) if (formValues) { swal(JSON.stringify(formValues)) }

limonte commented 6 years ago

@g4b0-88 SweetAlert2 is a different project, it's repo is https://github.com/sweetalert2/sweetalert2

t4t5 commented 6 years ago

@HadiAkmal Take a look at https://sweetalert.js.org/guides/#using-dom-nodes-as-content. You'll have to use swal.setActionValue if you want the promise to resolve a custom value (in this case, an array of strings seems right).