• 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

validwhen or ?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I've a simple jsp page with 2 textbox [TB1 and TB2] and 2 submit buttons [SB1 and SB2]. TB2 and SB2 is hidden inside a "DIV". Onclick of SB1 it validates TB1 and displayes the DIV part. Similarly SB2 validates TB2.
In validation.xml I've written like --

<field property="TB1" depends="required">
<msg name="required" key="error.required"/>
<arg0 key="Form.TB1.name"/>
</field>
<field property="TB2" depends="required,validwhen">
<msg name="required" key="error.required"/>
<arg0 key="Form.TB2.name"/>
<var>
<var-name>test</var-name>
<var-value>((submitButton != SB1))</var-value>
<!-- I've tried using (submitButton == SB2) also -->
</var>
</field>

But it is not working and onclick of SB1 it is displaying error message like "TB2 is required" and "DIV" part is never displayed.

Is my approach all right? Is there any alternate way to validate TB2??
[ March 19, 2008: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My understanding is that the validwhen rule does not work for client-side validation. I'd suggest writing your own JavaScript code to perform this validation.
 
aMIt dAs gUPTa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill,
First of all thanks for your suggestion.
And also sorry as I was not able to post my problem properly. I have taken care of displaying the DIV part in javascript. I have the client side validation for both the fields. But my requirement is to incorporate server side validation along with client side validations. Herein lies the problem as stated. Is there any problem with my validwhen syntax?
 
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
Looking at your validation for TB2, it doesn't make any sense to have both validwhen and required as a dependency. If the required rule is used, then the field is required no matter what. I'd suggest you make only validwhen the dependency, and change the test to:

If you think about it, the test expression should specify the conditions for which the field is valid. If SB2 is not pressed, the field is valid regardless. If SB2 is pressed, the test is only valid if TB2 is not null. Make sense?

Also, for the above to work the submit button must look like this:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic