OK - this is the approach I intend to take. Please let me know if I am on
the right path - or any links or pointers would also help.

My application is currently a jsp page that shows some tabs. Each tab is an
object that has various properties like name, code, id etc.

Clicking on each tab brings up a pop-up (simple using jquery show & hide)
The pop-up which is basically a form shows the properties as text fields and
can be modified.
There is a submit button at the bottom of this pop up / form that will
submit the form and post the action to another jsp (update.jsp say) that
will update the tables with the data in the database.

I am also using the validation plugin - bassistance. The client side
validation was quite trivial to do, like the id should be digits only,
required fields etc.

I need to extend these validation rules to the server-side like for example
the id needs to be unique in the table and a duplicate value should show an
error message as "Id already exists"

I am planning to address this requirement by using
jQuery.validator.addMethod to add a new custom validation.
In this validation I will check for an element errors. If the value of this
element "errors" is true, then I will display an error message. The code
will roughly be like this:

jQuery.validator.addMethod(
        "servererrors",
        function(value, element) {
            if (element.value == "true")
            {
                return false;
            }
            else return true;
        },
        "Errors on the form, please fix."
    );

(I intend to fine tune this further once I grasp the concept - so I admit
the validation is crude now)
In my form (the popup actually) I will add a new hidden field "errors" that
will be populated from update.jsp based on server side rules.

In my form (pop up) I will add this as a rule to one of the fields -
probably the first one so the error message appears adjacent to it.
Something along these lines....

$(function() {
    $('.main-title').click(function(event) {
    var v = $(event.target).parent();
    v.validate({
        rules: {
            regionid:
            {
                required: true,
                enter01: true,
                servererrors: true
            }
        }
     }
  }
}

Is my approach correct or is there something simpler / best practice? Also I
am not sure if my pop up will stay during all this validation, or will it
just close and I will have to figure out a way to display the pop-up again?
Finally should the error / validation message be associated to a visible
field only so that it is visible and adjacent to that field?

Any help is very much appreciated.

Thanks,
Anoop


On Wed, Jul 15, 2009 at 12:49 AM, Anoop kumar V <anoopkum...@gmail.com>wrote:

> Hi All,
>
> I was wondering if there is a link or pointers for best practices while
> integrating client side validation errors with server side validation. I
> read on a forum that this requires the server side to return a json, but
> could not find many pointers or details about this.
>
> Can somebody please provide some tips on how best to achieve this? By the
> way I am using the bassistance plugin, my application is a legacy app
> written in jsp & is database intensive; And so far I have not considered
> using ajaxform etc..
>
> Thanks,
> Anoop
>

Reply via email to