• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unable to trigger javascript validation

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Yeah, but how did the squirrel get in there? Was it because of the tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic