You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Erez Efrati <er...@netmedia.net.il> on 2003/05/09 19:13:32 UTC
Validator 'required' question - please help
Hi all,
I am using the Struts 1.1 beta3 version and in my validator.xml I have
written:
<form name="signupForm">
<field property="user.firstName"
depends="required"
page="1">
<arg0 key="userInfo.firstName"/>
</field>
</form>
The thing is on the client-side it only checks if the field is not
empty, but passes fields with just Whitespaces. On the other hand on the
server side the check is full - both emptiness and whitespaces are
checked. Why? Have I forget to do something here?
Regards
-- Erez
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: Validator 'required' question - please help
Posted by Erez Efrati <er...@netmedia.net.il>.
Thanks Mark, I am using the validator-rules.xml from 1.1 beat 3. And
yes, I am referring the validator-generated Javascript.
Here is a copy of the validator part of the 'required' taken from the
validator-rules.xml:
<validator name="required"
classname="org.apache.struts.validator.FieldChecks"
method="validateRequired"
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.required">
<javascript><![CDATA[
function validateRequired(form) {
var bValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
oRequired = new required();
for (x in oRequired) {
var field = form[oRequired[x][0]];
if (field.type == 'text' ||
field.type == 'textarea' ||
field.type == 'select-one' ||
field.type == 'radio' ||
field.type == 'password') {
var value;
// get field's value
if (field.type ==
"select-one") {
var si =
field.selectedIndex;
value =
field.options[si].value;
} else {
value =
field.value;
}
if (value == '') {
if (i == 0) {
focusField = field;
}
fields[i++] = oRequired[x][1];
bValid = false;
}
}
}
if (fields.length > 0) {
focusField.focus();
alert(fields.join('\n'));
}
return bValid;
}]]>
</javascript>
</validator>
Thanks,
-- Erez
-----Original Message-----
From: Mark Galbreath [mailto:mark_galbreath@qat.com]
Sent: Friday, May 09, 2003 7:24 PM
To: 'Struts Users Mailing List'
Subject: RE: Validator 'required' question - please help
What do you use on the client to validate, JavaScript? Are you relying
on
the Validator-generated JavaScript? We could be of more help if you
posted
the validation code.
Mark
-----Original Message-----
From: Erez Efrati [mailto:ereze@netmedia.net.il]
Sent: Friday, May 09, 2003 1:14 PM
Hi all,
I am using the Struts 1.1 beta3 version and in my validator.xml I have
written:
<form name="signupForm">
<field property="user.firstName"
depends="required"
page="1">
<arg0 key="userInfo.firstName"/>
</field>
</form>
The thing is on the client-side it only checks if the field is not
empty,
but passes fields with just Whitespaces. On the other hand on the server
side the check is full - both emptiness and whitespaces are checked.
Why?
Have I forget to do something here?
Regards
-- Erez
---------------------------------------------------------------------
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: Validator 'required' question - please help
Posted by Mark Galbreath <ma...@qat.com>.
What do you use on the client to validate, JavaScript? Are you relying on
the Validator-generated JavaScript? We could be of more help if you posted
the validation code.
Mark
-----Original Message-----
From: Erez Efrati [mailto:ereze@netmedia.net.il]
Sent: Friday, May 09, 2003 1:14 PM
Hi all,
I am using the Struts 1.1 beta3 version and in my validator.xml I have
written:
<form name="signupForm">
<field property="user.firstName"
depends="required"
page="1">
<arg0 key="userInfo.firstName"/>
</field>
</form>
The thing is on the client-side it only checks if the field is not empty,
but passes fields with just Whitespaces. On the other hand on the server
side the check is full - both emptiness and whitespaces are checked. Why?
Have I forget to do something here?
Regards
-- Erez
---------------------------------------------------------------------
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