Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught Error: Syntax error, unrecognized expression: label[for='days[]'], label[for='days[]'] *, #days[]-error #1504

Closed
albert28 opened this issue Jun 23, 2015 · 6 comments

Comments

@albert28
Copy link

Hi :D, the first time I validate if, at least, there is one checkbox selected, the form validator works ok. Nonetheless, the second time I keep getting this error no matter if the checkbox is selected or not.

Uncaught Error: Syntax error, unrecognized expression: label[for='days[]'], label[for='days[]'] *, #days[]-error

Here's my HTML:

<div class="checkbox-list">
 <input type="checkbox" class="days" name="days[]" />Mon
 <input type="checkbox" class="days" name="days[]" />Tue
 <input type="checkbox" class="days" name="days[]" />Wed
</div>

Here's my Javascript inside form.validate

'days[]': {
 atLeastOneChecked: true
}

And here's my Javascript inside jQuery.validator.addMethod

jQuery.validator.addMethod("atLeastOneChecked",function(value, element, params) {
 var selectedDays=($('.days:checked').size());
 if (selectedDays>0) return true;
 else return false;
}, "Please, select one day at least");
@jzaefferer
Copy link
Collaborator

I can't reproduce this. Can you test with the code in master in this git repository? At testpage that shows the issue would also help. I can then reopen if it persists.

@albert28
Copy link
Author

albert28 commented Jul 1, 2015

Thank you, but I already solved the problem. :)

@vierkantemeter
Copy link

Hi Albert28, I'm having the exact same problem. Do you remember how you fixed this?

@albert28
Copy link
Author

albert28 commented Oct 8, 2015

Hi, vierkantemeter. Notice I changed "days[]" to simply "days" in HTML and Javascript.

<div class="checkbox-list">
 <input type="checkbox" class="days" name="days" />Mon
 <input type="checkbox" class="days" name="days" />Tue
 <input type="checkbox" class="days" name="days" />Wed
</div>
jQuery.validator.addMethod("atLeastOneChecked",function(value, element, params) {
   var selectedDays=($('.days:checked').size());
   return (selectedDays >0);
}, "Please, select one day at least");
rules: { 
   days: { //this references input[name=days]!
      atLeastOneChecked: true
   }
}

@vierkantemeter
Copy link

Thank you Albert!

  • Michèlle

@staabm
Copy link
Member

staabm commented Oct 9, 2015

Fixed with c604e51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants