aspose file tools*
The moose likes Struts and the fly likes unable to trigger javascript validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "unable to trigger javascript validation" Watch "unable to trigger javascript validation" New topic
Author

unable to trigger javascript validation

jonathan Greens
Ranch Hand

Joined: Apr 07, 2004
Posts: 139
hi folks,
I have a bunch of <html:radios...> in my form. if none of them is selected, then the server side validation is triggered correctly. However, the javascript validation let it pass(the validation function was called).
for example, the radios' name is x, the form's name is f,and there is 1 radio button in the form with the value v. If none of the radio's name is selected, alert(f.x.value)shows that a value v, is this why the validator let it pass?
If so, how am I suppose to validate the radio buttons correctly??


thanks!!
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You may have to write your own javaScript validation, checking to see whether all the buttons in a given group are unchecked. Something like:

[ March 21, 2005: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
jonathan Greens
Ranch Hand

Joined: Apr 07, 2004
Posts: 139
So validation of radio button is not something that struts validation framework handles? So suppose a form contains a variety of things like radiobuttons, textfields,etc. some of hte validation will be done by struts and some by me.. this seems cumbersome. What's the challenge of validating radio buttons. Will struts implement this in the future version?

thanks!
[ March 21, 2005: Message edited by: jonathan Greens ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Jonathan,

While it would be nice if the "required" validation test provide by struts handled this situation, it doesn't appear to. However, the validation framework was meant to be extended, and you could write your own extension to handle this situation.

I haven't really looked into it, because I normally just write my own javaScript validation, and don't try to work with the validation framework.

However, you can add your own validators to the validator-rules.xml. Below is a url that shows an example of someone writing their own javaScript function and including it as a validator rule:

http://www.raibledesigns.com/page/rd/20030226

You could create a rule called "radioRequired" or something like that, and include a javascript function to handle it.

P.S.

I just noticed the example I gave you in my previous post was wrong. It should read:


When you have a more than one form control with the same name, javaScript interprets it as an array of controls.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unable to trigger javascript validation