Solved

Jquery validation by class

Posted on 2012-03-24
4
294 Views
Last Modified: 2012-03-26
Hello experts.
I need help to validate a form in a modal window by classname using jquery validation plugin.
My form is  id="formcategories"
My required textfields : class="categoryclass"

If one of the textfields doesn't pass the validation - add to this class error (like i would handle this with id validation)
Attached my code
var editcategory = function(id){
    var p = $("#popuploader");
    p.dialog({
        autoOpen: false,
        width: 300,
        height: 300
    });
    p.dialog({
       buttons: {
            "Save": function () {
                var targetUrl = "index.cfm";
                var b = $("#formcategories");
                var a = b.valid();
                if (a) {
                    var f = b.serialize();
                    $.post("actions/actupdate.cfm", f, function (g) {
                        if (g) {
                            
							window.location.href = targetUrl;
                           
                        }
                    })
                }
            
            },
            "Cancel": function () {
                $(this).dialog("close");
                $(this).dialog("destroy");
            }
        }
    });
	p.dialog("open");
	p.load("forms/frmtext.cfm?categoryid=" + id, function (c, e, d) {
            if (e == "success") {
			 $("#formcategories").validate({
				 
				 }
			   )
	
            } else {
                alert("errorload")
            }
        });
};

Open in new window


Any help?
0
Comment
Question by:Panos
  • 3
4 Comments
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 500 total points
ID: 37760544
This will will add the rule "required" to all fields of class "categoryclass":

$.validator.addClassRules({
  categoryclass: {
    required: true
  }
});

Open in new window


you can add more rules inside that.
0
 
LVL 2

Author Comment

by:Panos
ID: 37760698
Hi designatedinitializer
where do i have to place this code inside my script so that the form will be validated on:
var a = b.valid();
0
 
LVL 2

Author Comment

by:Panos
ID: 37765545
Finally i got it.
Thank you for your help
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 37765547
thank you
regards
panos
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question