[Answer]-Using jquery to validate forms in django

1👍

As per the jQuery Validation plugin documentation you must use messages and not message.

The plugin also works for an entire form not one form field at a time, please read the documentation thoroughly.

According to the docs something like this should work for you:

jQuery(function(){
    /* You do not need to use jQuery instead of $ inside of a jQuery declared function */
    $("#form_id").validate({
        rules: {
            /* #task_name name */
            name1: "required",
            /* #task_city name */
            name2: "required",
            /* #task_address name */
            name3: "required",
            /* #task_desc name */
            name4: "required",
            /* #task_price name */
            name5: "required"
        },
        messages: {
           name1: "please enter task name",
           name2: "please enter task city",
           name3: "please enter task address",
           name4: "please enter task desc",
           name5: "please enter task price",
       }
    });
});​
👤A.M.K

0👍

Django will prefix form fields with ‘id_’ in addition to any prefix you may have added to the form to prevent naming collisions between form classes with identical fields. I’m betting that you’re simply referencing the fields by ID incorrectly. Inspect the DOM of your rendered template with Firebug or similar inspection utility and make sure you’re referencing the fields by the correct ID.

Leave a comment