Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

ex

  • Loading branch information...
commit b19e8bd6b6e7af41e7f244517579605f31a6cc08 1 parent 898f7f8
authored June 27, 2011

Showing 1 changed file with 33 additions and 0 deletions. Show diff stats Hide diff stats

  1. 33  jquery.validate.max.js
33  jquery.validate.max.js
... ...
@@ -0,0 +1,33 @@
  1
+// jquery example to choose at least 1 checkbox but no more than 3
  2
+
  3
+$.validator.addMethod("checkboxes", function(value, element) {
  4
+  return $('input[type=checkbox]:checked').length < 4;
  5
+});
  6
+
  7
+// define validation
  8
+var validateForm = myForm.validate({
  9
+  ignore: ".ignore",
  10
+  errorElement: "strong",
  11
+  rules: {
  12
+    'select-checkbox[]' : { checkboxes: true }
  13
+  },
  14
+  messages: {
  15
+    title: 
  16
+      { required: "Please enter a title" },
  17
+    "select-checkbox[]":
  18
+      { required: "Please select up to 3 checkboxes",
  19
+        checkboxes: "Please select up to 3 checkboxes"},
  20
+    radiobuttons: 
  21
+      { required: "Please choose the radio button you want" },
  22
+    "selectbox-selected":
  23
+      { required: "At least 1 checkbox must be selected"}
  24
+  },
  25
+  errorPlacement: function(error, element) {
  26
+    if (element.is(":radio"))
  27
+      { error.appendTo(element.parents().eq(1).find(".error-item")); }
  28
+    else if (element.is(":checkbox"))
  29
+      { error.appendTo(element.parents().eq(1).find(".error-item")); }
  30
+    else
  31
+      { error.appendTo(element.parent()); }
  32
+   }
  33
+});

0 notes on commit b19e8bd

Please sign in to comment.
Something went wrong with that request. Please try again.