EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: devnull on January 28, 2015, 07:21:48 PM



Title: syncronous prompt window / messager
Post by: devnull on January 28, 2015, 07:21:48 PM
I need a synchronous dialog / window that allows me to have a few input elements for user input, rather than just one single element as per the jajascript prompt().

Can this be done ? - I need a callback once thse user clicks OK, but I also need to show a couple of comboboxes and inputs and return the data when the user clicks OK

 


Title: Re: syncronous prompt window / messager
Post by: devnull on January 28, 2015, 07:38:47 PM
Can the messager prompt be modified so that it parses the inputs in the dialog into a json string and sends that back as a single variable ?


Title: Re: syncronous prompt window / messager
Post by: stworthy on January 28, 2015, 08:28:39 PM
Defining a customized dialog to achieve this functionality may be more appropriate.
Code:
function showPrompt(title, href, fn){
var dlg = $('<div></div>').appendTo('body').dialog({
width: 300,
height: 150,
title: title,
href: href,
modal: true,
buttons:[{
text: 'Ok',
handler: function(){
var d = $(this).closest('div.panel').find('div.panel-body');
var json = d.find('form').serialize();
fn(json);
d.dialog('destroy');
}
},{
text: 'Cancel',
handler: function(){
var d = $(this).closest('div.panel').find('div.panel-body');
d.dialog('destroy');
}
}],
onClose: function(){
$(this).dialog('destroy');
}
}).dialog('dialog').find('.dialog-button').css('text-align','center')
}

Usage example:
Code:
showPrompt('Prompt', '_form.html', function(json){
  console.log(json);
});


Title: Re: syncronous prompt window / messager
Post by: devnull on January 29, 2015, 02:23:40 AM
Thanks, but what I am looking for is something similar to the standard javascript prompt() which freezes the calling script execution until a reply is received.

Using a callback from a normal window means that the calling code continues to run after the dialog is called.



Title: Re: syncronous prompt window / messager
Post by: stworthy on January 29, 2015, 07:52:24 AM
The $.messager.prompt and the 'showPrompt' functions work asynchronously. The user can not pause the code executing after calling these functions.