0

I'm creating popup forms using jQuery dialog & validation plugin. It all works fine except one thing - the error message doesn't clear off when form is closed, i.e. the form does not "reset" itself back to its initial state when user close the form.

My codes are as follows:

HTML

<div id="popupfrm" title="Action Plan Details">
  <form id="frmAClientActionPlanDetails" method="post" action="">
    <ul>
      <li>
        <label id="lActionPlanTitle" for="lActionPlanTitle">Action Plan Title*:</label>
        <input id="iActionPlanTitle" name="iActionPlanTitle" class="text" size="50" />
      </li>
      <li id="iActionPlanTitleMsg" class="errorStr"></li>
      <li>
        <label id="lDescription" for="lDescription">Description*:</label>
        <input id="iDescription" name="iDescription" class="text" size="50" />
      </li>
      <li id="iDescriptionMsg" class="errorStr"></li>
      <li>
        <label id="lNotes" for="lNotes">Notes:</label>
        <textarea id="iNotes" name="iNotes" cols="35" rows="4" class="text"></textarea>
      </li>
      <li id="iNotesMsg" class="errorStr"></li>
      <li>
        <label id="lDateUploaded" for="lDateUploaded">Date Uploaded:</label>
        <input id="iDateUploaded" name="iDateUploaded" class="text" size="50" maxlength="10" readonly="readonly" />
      </li>
      <li id="iDateUploadedMsg" class="errorStr"></li>
      <li>
        <label id="lFileUploaded" for="lFileUploaded">File Uploaded:</label>
        <input id="iFileUploaded" name="iFileUploaded" type="file" value=""/>
      </li>
      <li id="iFileUploadedMsg" class="errorStr"></li>
      <li><br />
      </li>
      <li> 
        <input type="submit" id="btnUpdate" name="btnUpdate" value="Update" class="button" /> 
      </li>
    </ul>
  </form>
</div>

JS - dialog

$(document).ready(function(){
    var iActionPlanTitle = $( "#iActionPlanTitle" ),
        iDescription = $( "#iDescription" ),
        iNotes = $( "#iNotes" ),
        iFileUploaded = $( "#iFileUploaded" ),
        allFields = $( [] ).add( iActionPlanTitle ).add( iDescription ).add( iNotes ).add( iFileUploaded );
alert(allFields);       

    $('#popupfrm').dialog({
        autoOpen: false,
        width: 600,
        modal: true,
        close: function() {
            allFields.val( "" ).removeClass( "error" );
        }
    });

    // Popup Links
    $('#popupfrm_link').click(function(){
        $('#popupfrm').dialog('open');
        return false;
    });
    $('#popupfrm_link2').click(function(){
        $('#popupfrm').dialog('open');
        return false;
    });

    //hover states on the static widgets
    $('#popupfrm_link, ul#icons li').hover(
        function() { $(this).addClass('ui-state-hover'); }, 
        function() { $(this).removeClass('ui-state-hover'); }
    );

});

JS - validation

$('#frmAClientActionPlanDetails').validate({
    rules: {
        iActionPlanTitle: {
            required: true,
            minlength: 2
        },
        iDescription: {
            required: true,
            minlength: 2
        }
    },
    messages: {
    iActionPlanTitle: {
        required: "Please enter a title."
    },      
    iDescription: {
        required: "Please enter a description."
    }   
    },
    errorElement: "li",
});

Can anyone please advise? Thanks!

2 Answers 2

1

On closing the dialog box, you have to clear the errormsg string value :

close: function() {
 .
 . 
   $('#iFileUploadedMsg').val('');
 .
 . 
  }
Sign up to request clarification or add additional context in comments.

Comments

0

Debug your page and check what is the class or id your error labels are taking. Then based on those attributes you can clear text from them.
For clearing you can use something like this:

$(id).html('');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.