JQuery clean old dialog
I am trying to use a UI dialog to create a modal dialog.
The dialogue is working properly and everything is fine. I close the dialog using the "X" in the corner. I tried to use dialog('destroy').remove();
, but of course I cannot open it again.
I think I just don't understand how to re-initialize the dialog and not have the old values ββin it.
function CreateWorkBoard()
{
var jsmarty = WMCreateSmartyObject();
var param =
{
MY_NAME1:GLOBAL_MY_NAME1,
MY_NAME2:GLOBAL_MY_NAME2,
LANG_NAME:LANGUAGE_NAME,
BOARD_DIALOG_TITLE:WM_LANG_BOARD_DIALOG_BOARD_DIALOG_TITLE,
BOARD_TITLE: WM_LANG_BOARD_DIALOG_BOARD_TITLE,
COMMENT_TITLE:WM_LANG_BOARD_DIALOG_COMMENT_TITLE,
MEMBERS_TITLE:WM_LANG_BOARD_DIALOG_MEMBERS_TITLE,
CANCEL_BUTTON:WM_LANG_BOARD_DIALOG_CANCEL_BUTTON,
REGISTER_BUTTON:WM_LANG_BOARD_DIALOG_REGISTER_BUTTON
};
jsmarty.assign('LANG', param);
var divValue = WMSmartyFetch(jsmarty, 'createBoardDialog.tpl');
document.getElementById('CREATE_DIALOG').innerHTML = divValue;
jsmarty.clear_all_assign();
//alert(document.getElementById('CREATE_DIALOG').innerHTML);
//alert(divValue);
//$.ui.dialog.defaults.bgiframe = true;
//alert(document.getElementById('New_WorkBoard_Dialog').innerHTML);
$('#New_WorkBoard_Dialog').dialog({
autoOpen: false,
height: 530,
width:300,
modal: true,
resizable:false,
buttons: {
Cancel: function() {
$(this).dialog('close');
//$('#New_WorkBoard_Dialog').dialog('destroy');
},
'Register board': function() {
var board_name=document.getElementById("name");
var comments=document.getElementById("comment");
Createboard(board_name,comments);
$(this).dialog('close');
}
},
close: function() {
}
});
$('#New_WorkBoard_Dialog').dialog('open');
}
As Ra Yell said, it's best to clear it before closing so that you don't have to worry about it when you reopen the dialogue.
$('input').val('');
The previous instruction worked for me.
You can clear all input elements dynamically.
$("#New_WorkBoard_Dialog input[type='text']").each(function(index, element) {
$(element).val("");
)};
If you prefer, you can clear it when you close the dialog:
$('#New_WorkBoard_Dialog').dialog({
autoOpen: false,
height: 530,
width:300,
modal: true,
resizable:false,
buttons: {
Cancel: function() {
$(this).dialog('close');
//$('#New_WorkBoard_Dialog').dialog('destroy');
},
'Register board': function() {
var board_name=document.getElementById("name");
var comments=document.getElementById("comment");
Createboard(board_name,comments);
$(this).dialog('close');
}
},
close: function() {
$("#New_WorkBoard_Dialog input[type='text']").each(function(index, element) {
$(element).val("");
)};
}
});
If you want to reopen it again, just use this code again:
$('#New_WorkBoard_Dialog').dialog('open');
Don't try to destroy and reinitialize the dialog. There is no need.