Help needed with rules for clientside validation in Struts
Hello!I'm struggling with a form developed with the struts validation framework.
To give you an idea of how the form looks like please take a look below:
<html:form action="/ProductFormAction" method="post" onsubmit="return validateProductForm(this);">
<table align="center">
<tr>
<td colspan="2" class="TD_CENTER">
<html:errors/>
</td>
</tr>
<tr>
<td class="TEXT_VERDANA_BLACK_10">
Select mobile phone number
</td>
<td class="TEXT_VERDANA_BLACK_10">
<html:select property="productselectlist">
<html:options collection="products" property="id" labelProperty="mobilephonenumber"/>
</html:select>
</td>
</tr>
<tr>
<td class="TEXT_VERDANA_BLACK_10">Add new product (mobile phone number)</td>
<td>
<html:text property="mobilephonenumber" size="25" maxlength="50" />
</td>
</tr>
<tr>
<td class="TEXT_VERDANA_BLACK_10" colspan="2">
<table>
<td>
<html:submit property="submitbutton">Add product</html:submit>
</td>
<td>
<html:submit property="submitbutton">Remove product</html:submit>
</td>
<td>
<html:submit property="submitbutton">Update product</html:submit>
</td>
<td>
<html:submit property="submitbutton">Select product</html:submit>
</td>
</table>
</td>
</tr>
<html:javascript formName="ProductForm"/>
</html:form>
</table>
The form contains:
1 selectlist called productselectlist
1 textfeild called mobilephonenumber
4 submit buttons called submitbutton with 4 different values (Add product, Remove product, Update product, Select product).
If the user pushes "Add product" then mobilephonenumber needs to be (required, minlength, maxlength, mask)
If the user pushes "Remove product" then productselectlist must be selected.
If the user pushes "Select product" then productselectlist must be selected.
If the user pushes "Update product" then productselectlist must be selected and mobilephonenumber needs to be (required, minlength, maxlength, mask).
Unfortunately I do not mange to set up the validation rules for this for the clientside so if some one could give me a hand with this it would be great. Below is my attempt to set up the rules. But for eg. if I push the "Remove product" the "Add product" - rule executes.
<formset>
<form name="ProductForm">
<field property="mobilephonenumber" depends="validwhen, required, minlength, maxlength, mask">
<arg key="ProductForm.clientsidevalidation.mobilephonenumber" />
<var>
<var-name>validwhenvar</var-name>
<var-value>((submitbutton == "Add product") or (submitbutton == "Update product"))</var-value>
</var>
<var>
<var-name>minlength</var-name>
<var-value>5</var-value>
</var>
<var>
<var-name>maxlength</var-name>
<var-value>50</var-value>
</var>
<var>
<var-name>mask</var-name>
<var-value>^[0-9]*$</var-value>
</var>
</field>
<field property="productselectlist" depends="validwhen">
<arg key="ProductForm.clientsidevalidation.productselectlist" />
<var>
<var-name>validwhenvar</var-name>
<var-value>((submitbutton == "Remove product") or (submitbutton == "Select product"))</var-value>
</var>
</field>
</form>
</formset>
Best regards
Fredrik
