I also wrote a andDependancy, that check to that a second and an optional third field are exist, if any one othe the three exist nice for things like optional three field phone numbers. Takes one var named secondField and an optional var thirdField.
On Thu, 30 Jan 2003 14:29:55 -0500
"Sri Sankaran" <[EMAIL PROTECTED]> wrote:
Man, that looks convoluted. Sri-----Original Message--------------------------------------------------------------------------
From: PILGRIM, Peter, FM [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 30, 2003 1:03 PM
To: 'Struts Users Mailing List'
Subject: RE: [VALIDATOR] requiredif ??
In the Struts User Guide there is a large example with indexed properties.
http://jakarta.apache.org/struts/userGuide/dev_validator.html
PS: I spend today resurrecting an old programmatical validation from a previous project. --
Peter Pilgrim,
Struts/J2EE Consultant, RBoS FM, Risk IT
Tel: +44 (0)207-375-4923
> -----Original Message-----
> From: Wendy Smoak [mailto:[EMAIL PROTECTED]]
> Sent: 30 January 2003 17:41
> To: 'Struts Users Mailing List'
> Subject: RE: [VALIDATOR] requiredif ??
> > > > I'm Still struggling with requiredif... there doesn't seem to
> be a working
> example of it included with 1.1b3. I've gone through the > documentation and
> come up with this. I'm trying to say that address is required only if
> 1. prospect is null
> 2. prospectNameOrId is not null
> 3. action is not equal to "Add Prospect"
> > <field property="address" depends="requiredif">
> <arg0 key="label.prospect.address"/>
> <var>
> <var-name>field[0]</var-name>
> <var-value>prospect</var-value>
> </var>
> <var>
> <var-name>field-test[0]</var-name>
> <var-value>NULL</var-value>
> </var>
> <var>
> <var-name>field[1]</var-name>
> <var-value>prospectNameOrId</var-value>
> </var>
> <var>
> <var-name>field-test[1]</var-name>
> <var-value>NOTNULL</var-value>
> </var>
> <var>
> <var-name>field[2]</var-name>
> <var-value>action</var-value>
> </var>
> <var>
> <var-name>field-test[2]</var-name>
> <var-value>NOTEQUAL</var-value>
> </var>
> <var>
> <var-name>field-value[2]</var-name>
> <var-value>Add Prospect</var-value>
> </var>
> <var>
> <var-name>field-join</var-name>
> <var-value>AND</var-value>
> </var>
> </field>
> > Thanks,
> > --
> Wendy Smoak
> Applications Systems Analyst, Sr.
> Arizona State University PA Information Resources Management
>
********************************************************************
Visit our Internet site at http://www.rbsmarkets.com
This e-mail is intended only for the addressee named above.
As this e-mail may contain confidential or privileged information,
if you are not the named addressee, you are not authorised to
retain, read, copy or disseminate this message or any part of it.
The Royal Bank of Scotland plc is registered in Scotland No 90312
Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB
Regulated by the Financial Services Authority
********************************************************************
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<validator name="andDependency" classname="org.glhec.fastadminas.util.StrutsValidator" method="validateAndDependency" methodParams="java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest" msg="errors.andRequired"> <javascript><![CDATA[ function validateAndDependency(form) { var bValid = true; var focusField = null; var i = 0; var fields = new Array(); oDependant = new andDependency(); for (x in oDependant) { if (( ((form[oDependant[x][0]].type == 'text' || form[oDependant[x][0]].type == 'textarea' || form[oDependant[x][0]].type == 'select-one' || form[oDependant[x][0]].type == 'radio' || form[oDependant[x][0]].type == 'password') && form[oDependant[x][0]].value != '') || ((form[oDependant[x][2]("secondField")].type == 'text' || form[oDependant[x][2]("secondField")].type == 'textarea' || form[oDependant[x][2]("secondField")].type == 'select-one' || form[oDependant[x][2]("secondField")].type == 'radio' || form[oDependant[x][2]("secondField")].type == 'password') && form[oDependant[x][2]("secondField")].value == '') || (oDependant[x][2]("thirdField") != "undefined" || ((form[oDependant[x][2]("thirdField")].type == 'text' || form[oDependant[x][2]("thirdField")].type == 'textarea' || form[oDependant[x][2]("thirdField")].type == 'select-one' || form[oDependant[x][2]("thirdField")].type == 'radio' || form[oDependant[x][2]("thirdField")].type == 'password') && form[oDependant[x][2]("thirdField")].value != ''))) && !(form[oDependant[x][0]].value != '' && form[oDependant[x][2]("secondField")].value != '' && (oDependant[x][2]("thirdField") == "undefined" || form[oDependant[x][2]("thirdField")].value != ''))) { if (i == 0) { focusField = form[oDependant[x][0]]; } fields[i++] = oDependant[x][1]; bValid = false; } } if (fields.length > 0) { focusField.focus(); alert(fields.join('\n')); } return bValid; }]]> </javascript> </validator> <validator name="xorDependency" classname="org.glhec.fastadminas.util.StrutsValidator" method="validateXorDependency" methodParams="java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest" msg="errors.orRequired"> <javascript><![CDATA[ function validateXorDependency(form) { var bValid = true; var focusField = null; var i = 0; var fields = new Array(); oDependant = new xorDependency(); for (x in oDependant) { if ((form[oDependant[x][0]].type == 'text' || form[oDependant[x][0]].type == 'textarea' || form[oDependant[x][0]].type == 'select-one' || form[oDependant[x][0]].type == 'radio' || form[oDependant[x][0]].type == 'password') && (form[oDependant[x][2]("secondField")].type == 'text' || form[oDependant[x][2]("secondField")].type == 'textarea' || form[oDependant[x][2]("secondField")].type == 'select-one' || form[oDependant[x][2]("secondField")].type == 'radio' || form[oDependant[x][2]("secondField")].type == 'password') && (form[oDependant[x][0]].value != '' && form[oDependant[x][2]("secondField")].value != '') || (form[oDependant[x][0]].value == '' && form[oDependant[x][2]("secondField")].value == '')) { if (i == 0) { focusField = form[oDependant[x][0]]; } fields[i++] = oDependant[x][1]; bValid = false; } } if (fields.length > 0) { focusField.focus(); alert(fields.join('\n')); } return bValid; }]]> </javascript> </validator>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]