aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Newbie question using jquery validator plugin on my JSF page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Newbie question using jquery validator plugin on my JSF page" Watch "Newbie question using jquery validator plugin on my JSF page" New topic
Author

Newbie question using jquery validator plugin on my JSF page

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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

Joined: Jan 10, 2002
Posts: 60992
    
  65

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

But to back up, why are you creating custom validation methods that all do the same thing?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

And
Is horribly verbose. Factor to:
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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

Joined: Jan 10, 2002
Posts: 60992
    
  65

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

Joined: Jun 21, 2005
Posts: 386

The line# 52 above:

$("#ARTransferForm\\:fromAccountAmt"): {
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

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

Joined: Jun 21, 2005
Posts: 386

Got it. Thanks.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Jan 10, 2002
Posts: 60992
    
  65

No problem -- every little bit helps!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Newbie question using jquery validator plugin on my JSF page