You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Joey Ebright <je...@attbi.com> on 2003/03/21 07:54:27 UTC

Validation - Require One of Multiple Fields

Hello,

I am looking for a way to validate that the user filled in at least one 
field of a possible many fields.  These fields represent search criteria 
to use for constructing an SQL query to a database and I want to ensure 
the user gives me at least one item to search on...

I looked at the requiredif validator but it is only server-side and I 
want both client side and server side validation.  If  I just wanted 
server side I could have written the validation code in my ActionForm 
myself...

I did come up with some rudimentary JavaScript to do this but am lost at 
how to do this in the same manner in a generic fashion on the server 
side.  The elegant approach of the validator framework on the client 
side is that it passes an array of fields that are to be validated and 
the validate method is only called once.  This allowed me in my 
JavaScript to just see if the addition of all the fields put together 
equaled an empty string.  On the server side, the framework differs in 
its approach to validation of fields and each field to be validated 
calls the validating method once.  Hence without reworking the validator 
framework, the same approach cannot be used - unless of course I am 
mistaken.  

Anyone else got some ideas out there???

TIA,
Joey



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Validation - Require One of Multiple Fields

Posted by Jeff Kyser <kt...@comcast.net>.
I think the requiredIf is still your best bet. I think based on other 
recent posts,
that the variable names have been changed to support javascript, but 
that code
may still be up to you to write.

-jeff

On Saturday, March 22, 2003, at 09:11  PM, Joey Ebright wrote:

> Thanks, but that is for making sure two fields are the same - I have 
> mastered that one...
>
> What I am after is making sure at least 1 of a group of fields has a 
> value filled in.  I don't care which one so long as at least one field 
> is filled in...
>
> Dan Tran wrote:
>
>> http://jakarta.apache.org/struts/userGuide/dev_validator.html
>>
>> may help. Look for twofield example.
>>
>> -D
>> ----- Original Message ----- From: "Joey Ebright" 
>> <je...@attbi.com>
>> To: <st...@jakarta.apache.org>
>> Sent: Thursday, March 20, 2003 10:54 PM
>> Subject: Validation - Require One of Multiple Fields
>>
>>
>>
>>> Hello,
>>>
>>> I am looking for a way to validate that the user filled in at least 
>>> one field of a possible many fields.  These fields represent search 
>>> criteria to use for constructing an SQL query to a database and I 
>>> want to ensure the user gives me at least one item to search on...
>>>
>>> I looked at the requiredif validator but it is only server-side and 
>>> I want both client side and server side validation.  If  I just 
>>> wanted server side I could have written the validation code in my 
>>> ActionForm myself...
>>>
>>> I did come up with some rudimentary JavaScript to do this but am 
>>> lost at how to do this in the same manner in a generic fashion on 
>>> the server side.  The elegant approach of the validator framework on 
>>> the client side is that it passes an array of fields that are to be 
>>> validated and the validate method is only called once.  This allowed 
>>> me in my JavaScript to just see if the addition of all the fields 
>>> put together equaled an empty string.  On the server side, the 
>>> framework differs in its approach to validation of fields and each 
>>> field to be validated calls the validating method once.  Hence 
>>> without reworking the validator framework, the same approach cannot 
>>> be used - unless of course I am mistaken.
>>> Anyone else got some ideas out there???
>>>
>>> TIA,
>>> Joey
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
>>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Validation - Require One of Multiple Fields

Posted by Joey Ebright <je...@attbi.com>.
Thanks, but that is for making sure two fields are the same - I have 
mastered that one...

What I am after is making sure at least 1 of a group of fields has a 
value filled in.  I don't care which one so long as at least one field 
is filled in...

Dan Tran wrote:

>http://jakarta.apache.org/struts/userGuide/dev_validator.html
>
>may help. Look for twofield example.
>
>-D
>----- Original Message ----- 
>From: "Joey Ebright" <je...@attbi.com>
>To: <st...@jakarta.apache.org>
>Sent: Thursday, March 20, 2003 10:54 PM
>Subject: Validation - Require One of Multiple Fields
>
>
>  
>
>>Hello,
>>
>>I am looking for a way to validate that the user filled in at least one 
>>field of a possible many fields.  These fields represent search criteria 
>>to use for constructing an SQL query to a database and I want to ensure 
>>the user gives me at least one item to search on...
>>
>>I looked at the requiredif validator but it is only server-side and I 
>>want both client side and server side validation.  If  I just wanted 
>>server side I could have written the validation code in my ActionForm 
>>myself...
>>
>>I did come up with some rudimentary JavaScript to do this but am lost at 
>>how to do this in the same manner in a generic fashion on the server 
>>side.  The elegant approach of the validator framework on the client 
>>side is that it passes an array of fields that are to be validated and 
>>the validate method is only called once.  This allowed me in my 
>>JavaScript to just see if the addition of all the fields put together 
>>equaled an empty string.  On the server side, the framework differs in 
>>its approach to validation of fields and each field to be validated 
>>calls the validating method once.  Hence without reworking the validator 
>>framework, the same approach cannot be used - unless of course I am 
>>mistaken.  
>>
>>Anyone else got some ideas out there???
>>
>>TIA,
>>Joey
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>  
>


Re: Validation - Require One of Multiple Fields

Posted by Dan Tran <da...@hotmail.com>.
http://jakarta.apache.org/struts/userGuide/dev_validator.html

may help. Look for twofield example.

-D
----- Original Message ----- 
From: "Joey Ebright" <je...@attbi.com>
To: <st...@jakarta.apache.org>
Sent: Thursday, March 20, 2003 10:54 PM
Subject: Validation - Require One of Multiple Fields


> Hello,
> 
> I am looking for a way to validate that the user filled in at least one 
> field of a possible many fields.  These fields represent search criteria 
> to use for constructing an SQL query to a database and I want to ensure 
> the user gives me at least one item to search on...
> 
> I looked at the requiredif validator but it is only server-side and I 
> want both client side and server side validation.  If  I just wanted 
> server side I could have written the validation code in my ActionForm 
> myself...
> 
> I did come up with some rudimentary JavaScript to do this but am lost at 
> how to do this in the same manner in a generic fashion on the server 
> side.  The elegant approach of the validator framework on the client 
> side is that it passes an array of fields that are to be validated and 
> the validate method is only called once.  This allowed me in my 
> JavaScript to just see if the addition of all the fields put together 
> equaled an empty string.  On the server side, the framework differs in 
> its approach to validation of fields and each field to be validated 
> calls the validating method once.  Hence without reworking the validator 
> framework, the same approach cannot be used - unless of course I am 
> mistaken.  
> 
> Anyone else got some ideas out there???
> 
> TIA,
> Joey
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org