t4t5 / sweetalert

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

Textarea input type Problem! #839

Open ingrocha opened 6 years ago

ingrocha commented 6 years ago
swal('Notas',{
    button: "Guardar",
    content:{
      element:"textarea",
         attributes: {
            placeholder: "Type your password",
            value: data.mensaje.clients.nota
         },
      }
    }).then((result) => {
         console.log(result);
    });

When i call result it gets 'true' it dosent get the vaue in the textarea

fmendoza commented 5 years ago

Same issue here. Any advice?

hellodit commented 3 years ago

hii @fmendoza and @ingrocha, we have same issue, after google an hour I've found the solution, here is example code from this source

$("#btn-show-feedback").click(function(){
  var textarea = document.createElement('textarea');
  textarea.rows = 6;
  textarea.className = 'swal-content__textarea';

  // Set swal return value every time an onkeyup event is fired in this textarea
  textarea.onkeyup = function () {
    swal.setActionValue({
      confirm: this.value
    });
  };

  swal({
    text: 'How can we improve this site?',
    content: textarea,
    buttons: {
      cancel: {
        text: 'Cancel',
        visible: true
      },
      confirm: {
        text: 'Submit',
        closeModal: false
      }
    }
  }).then(function (value) {
    if (value && value !== true && value !== '') {
      var data = { feedback: value };
      $.ajax({
        url: '/send-feedback',
        method: 'POST',
        data: data,
        success: function (res) {
          swal('Success', 'Feedback successfully submitted.', 'success');
        },
        error: function (err) {
          swal('Error', 'Unfortunately, an error occurred. Please try again.', 'error');
        }
      });
    }

    if (value === true || value === '') {
      swal.close();
    }
  });
});
williansmartins commented 2 years ago

@hellodit, works like a charm! But have i side effect...

This part not work more, attributes: { value: startValue, },