• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unable to trigger javascript validation

 
jonathan Greens
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
jonathan Greens
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic