Cancel modal dialog on close

I have a modal form that opens a reset password for the user.

<div id="password-form" title="Reset Password"> <form method="post"> <fieldset> <label for="emailreset">Enter Email Address</label> <input type="text" name="emailreset" id="emailreset" class="text ui-widget-content ui-corner-all" /> </fieldset> </form> </div> 

When the user clicks the reset password button, I call a function that checks if the user exists. after the success of the message, I change the contents of the div to the generated message. it all works as expected. Now what I want is to close the modal dialog once, I want the contents of reset to return to the form. I have problems with this. I tried different things, but his help in the work would not be appreciated.

this is what i have for jquery

 $( "#password-form" ).dialog({ autoOpen: false, height: 200, width: 300, modal: true, buttons: { "Reset Password": function() { $.ajax({ url: "/model/websitemanager.cfc" , type: "post" , dataType: "html" , data: { method: "resetpassword" , emailreset: $("#emailreset").val() } , success: function (data){ //alert(data); $('#password-form').html('<p>'+data+'</p>'); } // this runs if an error , error: function (xhr, textStatus, errorThrown){ // show error alert(errorThrown); } }); <!--//end ajax call//--> }, }, close: function() { emailreset.val( "" ).removeClass( "ui-state-error" ); $(this).dialog('destroy').remove() } }); 

Thanks in advance!

Jay

+4
source share
1 answer

Here's a simple feature available around the world around the world:

 function clearInputs(target) { $(target).find(':input').each(function () { switch (this.type) { case 'password': case 'select-multiple': case 'select-one': case 'text': case 'textarea': $(this).val(''); break; case 'checkbox': case 'radio': this.checked = false; } }); } 

And this is how I use it for jQuery dialogs:

 $('#myDialog').dialog({ buttons:{ 'Submit':function () { // Do something here clearInputs($(this).find('form')); $(this).dialog('close'); }, 'Cancel':function () { clearInputs($(this).find('form')); $(this).dialog('close'); } }, close:function () { clearInputs($(this).find('form')); } }); 
+2
source

All Articles