Permalink
Browse files

Fixed #189 - :hidden elements are now ignored by default

  • Loading branch information...
1 parent 665f67d commit 21707129666012f6b0bc60622eb3bcb9f87daa04 @hdragomir hdragomir committed with Sep 4, 2011
Showing with 29 additions and 1 deletion.
  1. +1 −0 changelog.txt
  2. +1 −1 jquery.validate.js
  3. +27 −0 test/test.js
View
1 changelog.txt
@@ -13,6 +13,7 @@
* Fixed #184 - resetForm: should unset lastElement
* Fixed #71 - improve existing time method and add time12h method for 12h am/pm time format
* Fixed #177 - Fix validation of a single radio or checkbox input
+* Fixed #189 - :hidden elements are now ignored by default
1.8.1
---
View
2 jquery.validate.js
@@ -214,7 +214,7 @@ $.extend($.validator, {
errorContainer: $( [] ),
errorLabelContainer: $( [] ),
onsubmit: true,
- ignore: [],
+ ignore: ":hidden",
ignoreTitle: false,
onfocusin: function(element) {
this.lastActive = element;
View
27 test/test.js
@@ -1159,3 +1159,30 @@ test("validate radio on click", function() {
trigger(e1);
errors(0);
});
+
+test("ignore hidden elements", function(){
+ var form = $('#userForm');
+ var validate = form.validate({
+ rules:{
+ "username": "required"
+ }
+ });
+ form.get(0).reset();
+ ok(! validate.form(), "form should be initially invalid");
+ $('#userForm [name=username]').hide();
+ ok(validate.form(), "hidden elements should be ignored by default");
+});
+
+test("ignore hidden elements at start", function(){
+ var form = $('#userForm');
+ var validate = form.validate({
+ rules:{
+ "username": "required"
+ }
+ });
+ form.get(0).reset();
+ $('#userForm [name=username]').hide();
+ ok(validate.form(), "hidden elements should be ignored by default");
+ $('#userForm [name=username]').show();
+ ok(! validate.form(), "form should be invalid when required element is visible");
+});

3 comments on commit 2170712

@Pathz88

Hi all... i have my div structure like this. only parent div is display none and child elements don't support for ignore:":hidden". what should i do..?

div id="divDepartmentArea" runat="server" style="display: none" clientidmode='Static'
div class="marginTop"
asp:TextBox ID="txtFrom" runat="server" ClientIDMode="Static" data-required="true"asp:TextBox
asp:TextBox ID="txtTo" runat="server" ClientIDMode="Static" data-required="true"asp:TextBox
/div
/div"

@staabm
Collaborator

@Pathz88 please open a new issue describing your problem in more detail

@Pathz88

@staabm i'm new to github and don't know much about creating issues.. but i think i made a one. you can find it in below link
#1595

please help me..

Please sign in to comment.