Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Newbie question using jquery validator plugin on my JSF page

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my JSF page I am trying to validate dropdown lists AND input fields and in reading the validator plugin, jquery-validation-1.8.1, documentation I tried using the following jQuery code to validate but I'm getting numerous errors:



Here are the errors I am getting:

1. When the page is attempting to load I get this error:
Expected ':'
index.jsp

2. When defining the jQuery.validator.addMethod for each of my dropdown lists in my IDE I am getting a red squiggly line under the addMethod and the error states: "The function addMethod(String, Function, String) is undefined". Yet in the documentation, it says that this is valid.

I have tried using just the ID from the input field but that did not work. Any help/direction would be greatly appreciated.

Thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Melinda Savoy wrote:
1. When the page is attempting to load I get this error:
Expected ':'
index.jsp

Where? On the server or the client? If on the client, on which line? Please take the time to provide adequate info.

2. When defining the jQuery.validator.addMethod for each of my dropdown lists in my IDE I am getting a red squiggly line under the addMethod and the error states: "The function addMethod(String, Function, String) is undefined". Yet in the documentation, it says that this is valid.

IDEs are notoriously poor at dealing with JavaScript. Fix the run-time errors then worry about the IDE. Or, are you sure that you've correctly included the script files?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But to back up, why are you creating custom validation methods that all do the same thing?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And
Is horribly verbose. Factor to:
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me try and respond to each of your responses accurately:

1. On the client side, sorry I was not more specific.
2. Yes, I've correctly included the script files.
3. I appreciate the response. Trying to clean that up right now by making it more generic(?). I had 3 separate dropdowns and therefore the reason for 3 custom validation methods.
4. Thanks for the feedback on the verbose code. Cleaned that up.

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Melinda Savoy wrote:1. On the client side, sorry I was not more specific.

Which line?

Melinda Savoy wrote:I had 3 separate dropdowns and therefore the reason for 3 custom validation methods.
There is no need to have a validation method for individual elements. The same validation method can be applied to any element.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The line# 52 above:

$("#ARTransferForm\\:fromAccountAmt"): {
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is with this syntax:
Melinda Savoy wrote:rules: {
$("#ARTransferForm\\:facilityCodes"): {
selectFacilityCodes: true
},

?

You are trying to use a jQuery wrapped set as a hash key and that's just not valid JavaScript.

According to the documentation for the validation plugin, that key must be the name attribute value for the input element that the rule is to be applied to.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it. Thanks.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,

JSF creates element ID's with a form name and element name combination. So if you have something like:



You end up with something like:



For jQuery to select based on the ID you have to escape the colon. Just wanted you to be aware of that as this thread continues.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I knew that. The colon in the selector isn't the issue. It's the attempted use of a jQuery wrapped set as a hash key.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Yes, I knew that. The colon in the selector isn't the issue. It's the attempted use of a jQuery wrapped set as a hash key.


Ah, ok. My bad.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem -- every little bit helps!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic