DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16885>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16885 client side validation strips off dashes in user defined variables in validation.xml Summary: client side validation strips off dashes in user defined variables in validation.xml Product: Struts Version: 1.1 Beta 3 Platform: PC OS/Version: Windows NT/2K Status: NEW Severity: Normal Priority: Other Component: Validator Framework AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Hello, I tried to implement a conditional mask in javascript in my validator- rules.xml. I take the mask originally as a string from validation.xml and generate a regexp object from that in validator-rules.xml. The source file (html) of the browser escaped all the dashes in my mask pattern correctly. What happens is the escaped dashes in my mask pattern all disappear when they come to the javascript function in validator-rules.xml. (printed out with alert). For example, I use '\w' to stand for all the word chars in my mask pattern in validation.xml, in the html created by jsp, it is '\\w', (it is always doubled in html page so if I give 4 dashes in validation, it is 8 in html, which does not work either ), but it is 'w' in the javascript function in validator- rules.xml. I tried it with the sample struts validator web application package (registration form and multi-registration form) and it is the same thing. But the server side validation takes the dashes correctly. I am using the 1.1- beta3. I didn't have this problem before until I updated my struts into 1.1- beta3. Can it be a bug? One more thing, may I know how I can define a global javascript function that can be used by a couple of validators in validator-rules.xml? Thank you for any help. ginger The related part in validation.xml: <field property="lastName" depends="cdnmask"> <msg name="cdnmask" key="registrationForm.lastname.maskmsg"/> <arg0 key="registrationForm.lastname.displayname"/> <var> <var-name>cdnProperty</var-name> <var-value>firstName</var-value> </var> <var> <var-name>cdnValue</var-name> <var-value>piggy</var-value> </var> <var> <var-name>conditionMask</var-name> <var-value>^\w*$</var-value> </var> </field> The related part in validator-rules.xml: <!--conditional mask, only tested when the value of condition property is cdnValue --> <validator name="cdnmask" classname="org.apache.struts.webapp.validator.Cvalidator" method="validateCdnMask" 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.invalid"> <javascript><![CDATA[ function validateCdnMask(form) { var bValid = true; var focusField = null; var i = 0; var fields = new Array(); oMask = new cdnmask(); for ( x in oMask ) { var conditionProperty = oMask[x][2]("cdnProperty"); var conditionValue = oMask[x][2]("cdnValue"); var mask = oMask[x][2]("conditionMask"); alert(" the mask at first (mask) is " + mask ); if ( (form[conditionProperty].value == conditionValue) && ( form[oMask[x][0]].value != '' ) && (!matchPattern2(form[oMask[x][0]].value, oMask[x][2]("conditionMask"))) ) { if (i == 0) { focusField = form[oMask[x][0]]; } fields[i++] = oMask[x][1]; bValid = false; } } if (fields.length > 0) { focusField.focus(); alert(fields.join('\n')); } return bValid; } function matchPattern2(value, mask) { alert("the string for mask is " + mask); var mask2 = new RegExp(mask); var bMatched = mask2.exec(value); if (!bMatched) { return false; } return true; }]]> </javascript> </validator> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]