You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Greg Hess <gh...@wrappedapps.com> on 2003/03/13 16:16:01 UTC

Mask validation BUG with requiredif

Hi All, 
 
I have just started using the requiredif validation rule with a field
that is also being validated with a mask rule. The server side
validation is working fine but the client side JavaScript has errors for
my requiredif form fields. 
My form field requires the feild button2URL only if button2Lbl has been
entered and if button2URL it must pass the mask rule. 
 
When I use my mask without the requiredif rule all is well in client
JavaScript the generated method is as follows:
 
function mask () { 
     this.aa = new Array("button2URL", "Button 2 URL must contain a
valid URL. For more information click the help icon.", new Function
("varName", "this.mask=/^http:\\/\\/|^file:\\/\\/|^mailto:[^ ]*$/;
return this[varName];"));
    } 
 
When the requiredif rule is added and the JavaScript breaks and the
generated method is:
 
function mask () { 
     this.aa = new Array("button2URL", "Button 2 URL must contain a
valid URL. For more information click the help icon.", new Function
("varName", "this.field-test[0]='NOTNULL'; this.field[0]='button2Lbl';
this.mask=/^http:\\/\\/|^file:\\/\\/|^mailto:[^ ]*$/;  return
this[varName];"));
    } 
 
Below is my validation def for this form:
 
<field property="button2Lbl" depends="required">
 
<arg0 key="wbConfigForm.button2Lbl"/>
 
</field>
 
<field property="button2URL" depends="requiredif,mask">
 
<msg name="mask" key="error.invalidURL"/>
 
<arg0 key="wbConfigForm.button2URL"/>
 
<var>
 
<var-name>mask</var-name>
 
<var-value>^http:\/\/|^file:\/\/|^mailto:[^ ]*$</var-value>
 
</var>
 
<var>
 
<var-name>field[0]</var-name>
 
<var-value>button2Lbl</var-value>
 
</var>
 
<var>
 
<var-name>field-test[0]</var-name>
 
<var-value>NOTNULL</var-value>
 
</var> 
 
</field>
 
</form>
 
I have accepted that for now I will create my own static JavaScript for
the form to handle the requirdif fields but I would still like to use
the other rules and their client side validation with my reqiredif
fields. 
 
Many thanks,
 
Greg
 

Re: Mask validation BUG with requiredif

Posted by Evan Schnell <es...@nvisia.com>.
Greg Hess wrote:

>Hi All, 
> 
>I have just started using the requiredif validation rule with a field
>that is also being validated with a mask rule. The server side
>validation is working fine but the client side JavaScript has errors for
>my requiredif form fields. 
>  
>
I cannot seem to get any client-side validation to work when requiredif 
is turned on.  I wrote my own javascript rule that is supposed to always 
return true.  However mozilla's javascript engine (and presumably IE's 
because both give the same end behavior) will not allow a variable to be 
named "field-test" or "field-join".  

Specifically the bug is in:

     this.ae = new Array("lastName", "Last Name can not be less than 2 
characters.", new Function ("varName",     "this.field[0]='firstName'; 
this.field-test[0]='NOTNULL'; this.minlength=2;  return this[varName];"));

The only workaround I can see is to follow advice previously posted on 
this list and not attempt client side "requiredif,"  Then I can hack 
JavascriptValidatorTag.java to support a new jsType called "omit" which 
will prevent the variable from being included in the javascript at all.

Regards, Evan.