I am trying to remove text in a dialog when a user closes the dialog. I have multiple dialogs in a page and some dialogs have forms inside of them. One of them is to send a message to a user and the other is a form to update user details.
When a form is submitted a message is displayed above the form about the status i.e. whether it failed or it was successful.
jQuery:
$('form.updateDetailsForm').on('submit', function()
{
//console.log("hello");
event.preventDefault();
var form = $(this);
post = form.serialize();
$.post("",{ form: post, studentHub: true}, function(msg)
{
var popUpDialog = form.parent();
console.log(msg);
var status = $('.notifications', popUpDialog);
status
.html(msg)
.hide()
.fadeTo(2500, 1)
.delay(20000)//<== wait 3 sec before fading out
.fadeTo(2000, 0, function()
{
status.html('');
});
});
//return false;
});//END OF updatedetails form submit
/****For each popuplink we bind the dialog that is ---IMMEDIATELY NEXT--- to it and click event to it. ***/
$('.popUpLink').each(function()
{
if(!$.data(this, 'dialog'))//if not bound then we bind it. This is for dynamic issues
{
$divDialog = $(this).next('.popUpDialog');
$.data(this, 'dialog', $divDialog.dialog(
{
autoOpen: false,
modal: true,
minWidth: '100',
width: '800',
hide: 'fold',
show: 'drop',
title: $divDialog.attr('title'),
close: function() {
$('.notifications, div:animated', $divDialog).html(''); //this is what I've tried but it doesn't work.
}
}));
}
}).on('click',function()
{
$.data(this, 'dialog').dialog('open').css('maxHeight', $(window).height()-90);
return false;
});
HTML:
<div class="flexi_box">
<h2 class="sendMessageHeader hubFormHeader">Send a message to your tutor </h2>
<div class="notifications"></div> //div to insert status updates
<form class="sendMessageForm" id="tutorForm" action="" method="POST">
<fieldset>
<textarea class="messageArea" name="message"></textarea>
<input type="submit" value="Send Message" class="cap_button hubSubmit">
</fieldset>
</form>
</div>
My problem is that the status updates are still there when I reopen the dialog.
I don't think the selector will work like this:
$('.notifications, div:animated', $divDialog).html(''); //this is what I've tried but it doesn't work.
The selection is coming back empty for me. Try separating them:
$('.notifications, div:animated').html('');
$divDialog.html('');