michelmanolo / jquery-datatables-editable

Automatically exported from code.google.com/p/jquery-datatables-editable
0 stars 0 forks source link

Add record form validation errors not cleared #27

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Click the add button to open the add form.
2. Leave a required field or fields blank.
3. Click the OK/Submit button to trigger the validation errors.
4. Click the cancel or close button to close the form.
5. Click the add button to re-open the form. The existing errors remain, 
instead of being cleared.

What version of the product are you using? 
1.2.5

Original issue reported on code.google.com by dmol...@gmail.com on 7 Jun 2011 at 6:22

GoogleCodeExporter commented 8 years ago
I fixed this by modifying the _fnOnCancelRowAdding(event) function to the 
following:

        //Called when user cancels adding new record in the popup dialog
function _fnOnCancelRowAdding(event) {
    //Close the dialog
    oAddNewRowForm.dialog('close');
    $(oAddNewRowForm).validate().resetForm();      <---- This is the line I added
    $(oAddNewRowForm)[0].reset();
    $(".error", $(oAddNewRowForm)).html("");
    event.stopPropagation();
    event.preventDefault();
}

Original comment by dmol...@gmail.com on 7 Jun 2011 at 7:14

GoogleCodeExporter commented 8 years ago
Also, if the user has the error messages displayed in a div with class "error", 
it won't be cleared properly if the form is closed after a validation error. 
The changes below fix that:

//Called when user cancels adding new record in the popup dialog
function _fnOnCancelRowAdding(event) {
//Close the dialog
   oAddNewRowForm.dialog('close');
   $(oAddNewRowForm).validate().resetForm();  // Clears the validation errors
   $(oAddNewRowForm)[0].reset();
   $("div.error span", $(oAddNewRowForm)).html("");
   $("div.error", $(oAddNewRowForm)).hide();  // Hides the error div
   event.stopPropagation();
   event.preventDefault();
}

Original comment by dmol...@gmail.com on 8 Jun 2011 at 11:20

GoogleCodeExporter commented 8 years ago
Hi,

I have not noticed this issue. I all my examples on the site, when error is 
shown following code clear the form and error labels:
    $(oAddNewRowForm)[0].reset();
    $(".error", $(oAddNewRowForm)).html("");
Only potential issue is that when user closes the form (e.g. click on the [x] 
button in the upper right corner), form/messages are not cleared (to enable 
user to continue with editing if he accidentelly closed the dialog).

However I have added your code because it does nto collide with the current 
code. The only change is that I have not included div in the selector because  
would not link to put any constraint such as "you must wrap error labels in the 
div tags".
Current code is:

        //Called when user cancels adding new record in the popup dialog
        function _fnOnCancelRowAdding(event) {
            //Clear the validation messages and reset form
            $(oAddNewRowForm).validate().resetForm();  // Clears the validation errors
            $(oAddNewRowForm)[0].reset();

            $(".error", $(oAddNewRowForm)).html("");
            $(".error", $(oAddNewRowForm)).hide();  // Hides the error element

            //Close the dialog
            oAddNewRowForm.dialog('close');
            event.stopPropagation();
            event.preventDefault();
        }

Could you please take the latest version and let me know whether it wrks in 
your example?

Thanks,
Jovan

Original comment by joc...@gmail.com on 11 Jun 2011 at 8:33

GoogleCodeExporter commented 8 years ago
This works. I have to include the div/span due to implementation details of my 
application.

Original comment by dmol...@gmail.com on 11 Jun 2011 at 11:06

GoogleCodeExporter commented 8 years ago
Ok,I'm closing this issue.

Original comment by joc...@gmail.com on 11 Jun 2011 at 3:24

GoogleCodeExporter commented 8 years ago
Just a note regarding this error: $(oAddNewRowForm)[0].reset is not a function

If you happen to have a form reset button with id="reset", this will cause this 
issue to occurr also.

Just a note to assist others.

Original comment by obj...@gmail.com on 13 Oct 2011 at 7:12