Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

use of requiredIf in validation.xml  RSS feed

 
Suddhasattwa Mukherjee
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
The condition is :I have two groups of radio button.
sex : Male & Female
Agegroup : 18-30 & 30 Above
On clicking on the diffrent radio button different sets of textbox displayed through JS.
Now I want to use validator :requiredIf or ValidWhen whatever it may be to ascertain that mandatory field for different set of radio button chosen must be filled.
Can anyone please help me with the code of validation.xml
Condition:Say when Sex Male & agegroup 18-30 selected Hobbies field must be given.
 
Alaa Nassef
Ranch Hand
Posts: 471
Hibernate Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't this be in the struts forum. Anyway, requiredIf is deprecated and you should use validWhen instead. Anyway, whether you use this or that, you have to define a variable called test, where you put you boolean expression. For example, if you use validWhen in your case, it should look something like this:



Which means that this field is valid when sex is not M or the age group is not the first one or the hobbies is not null. This means that if the user chooses both M and the first age group, then he MUST fill the hobbies field, or it won't be valid. You can build much more complex scenarios if you want.

As for requiredIf (which is deprecated as I stated before), you also define the test variable, and it will mean that this field is required if the following test succeeds. As you can see, validWhen is much better.
 
Suddhasattwa Mukherjee
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply...
But this code is not working for me.I have tried view source of that page and there is no validateValidWhen method created as for required and mask-it is created.I am using Struts 1.2.7 and also there is validwhen validator in validation-rules.xml files.
what would be the cause for this can you please suggest?
 
Alaa Nassef
Ranch Hand
Posts: 471
Hibernate Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. You should take this to the struts forum. You'll get more help there
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!