skip to Main Content
var form = document.createElement("div");
form.innerHTML = "<input type='text'  id='Test'>";

swal({
  content: form,
  closeOnEsc: false,
  closeOnClickOutside: false,
});

$('#Test').datepicker();

The swal is displayed without any problem and also input but when I click on input nothing happens.

When I do the same thing in body and out of swal(without sweet alert) its ok and datepicker is active and I can choose a time but the problem is happened when I using swal

2

Answers


  1. You could try the didOpen function:

    Popup lifecycle hook. Asynchronously runs after the popup has been
    shown on screen. Provides popup DOM element as the argument

    var form = document.createElement("div");
    form.innerHTML = "<input type='text'  id='Test'>";
    
    swal({
      content: form,
      closeOnEsc: false,
      closeOnClickOutside: false,
      didOpen:function(el){
        $('#Test').datepicker();
      }
    });
    
    Login or Signup to reply.
  2. Using didOpen with the current approach

    Swal.fire({
      title: 'My Form',
      html: `<input type='text'  id='Test'>`,
      didOpen: function () {
        $('#Test').datepicker();  
      }
    });
    <link href="https://code.jquery.com/ui/1.13.2/themes/black-tie/jquery-ui.css" rel="stylesheet"/>
    
    <script
      src="https://code.jquery.com/jquery-3.6.1.min.js"
      integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ="
      crossorigin="anonymous"></script>
    <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    
    
    <script
      src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"
      integrity="sha256-lSjKY0/srUM9BE3dPm+c4fBo1dky2v27Gdjm2uoZaL0="
      crossorigin="anonymous"></script>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search