EasyUI Forum
May 07, 2024, 05:32:04 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: messager.confirm in for loop [SOLVED]  (Read 3002 times)
jega
Full Member
***
Posts: 190


View Profile
« on: December 26, 2020, 08:10:36 AM »

Hi.

Have a for loop with a confirm messager box. When waiting for my answer, the loop runs to end and write "Test 0".
But when i remove the messager and only use confirm('Are you sure to send data'), the loop pause until my answer, and after answer it goes to console.log() and loops to next.

for (var i = 0; i < sendData.length; i++) {
   if (sendData == '1'){

      //var r = confirm("Are you sure to send data");

      $.messager.confirm({
         width:400,
         title: 'Test',
         msg: 'Are you sure to send data',
         ok: 'Yes',
         cancel: 'No',
         fn: function(r){
            sendFTPData(url,r)
         }
      });
   };
   console.log('Test '+i)
}

Regards
Jesper
« Last Edit: December 29, 2020, 12:41:20 PM by jega » Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: December 27, 2020, 02:24:23 AM »

The messager works in async mode, so you can't block it like the native 'confirm' function. Here is the possible way to send your array data with confirmation.
Code:
function confirmData(data){
  // filter the data to send
  data = data.filter(item => item == 1);
  // the data item index
  var index = 0;
  var el = $('<div></div>').on('confirm', function(){
    if (index < data.length){
      $.messager.confirm({
        title: 'Test',
        msg: 'Are you sure to send data?',
        fn: function(r){
          console.log('send '+index);
          index++;
          el.triggerHandler('confirm');
        }
      })
    }
  })
  el.triggerHandler('confirm');
}

var sendData = [1,2,1,3];
confirmData(sendData);

Logged
jega
Full Member
***
Posts: 190


View Profile
« Reply #2 on: December 29, 2020, 12:40:43 PM »

Thanks.

Works in my setup
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!