So I have created a custom search page that allows for me to search Customers by any field, and all the fields are optional. To do this, I had to create a custom <form:find> tag and comment out this line:
<!-- <script type="text/javascript">Spring.addDecoration(new Spring.ValidateAllDecoration({elementId:'proceed', event:'onclick'}));</script> -->
This allows me to submit the form. But here is the problem: if I click inside a field and click outside of it, without entering any text, the “This field is required” validation error pops up.
I can still submit the form, and the search page works, but I would like to fix this annoying, incorrect error.
Here is the .jspx
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:field="urn:jsptagdir:/WEB-INF/tags/form/fields" xmlns:form="urn:jsptagdir:/WEB-INF/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<jsp:output omit-xml-declaration="yes"/>
<form:find_without_validation finderName="ByOutputFormatAndStorageDeviceAndWorkOrderAndServiceOffering" id="ff_com_eg_egmedia_bizapp_model_ServiceItem" path="/serviceitems" z="b0NZUow+hQ11Ruy9n/4oyBOWOBs=">
<field:select_optional disableFormBinding="true" field="outputFormat" id="f_com_eg_egmedia_bizapp_model_ServiceItem_outputFormat" items="${outputformatenums}" path="/outputformatenums" required="false" z="user-managed"/>
<field:select_optional disableFormBinding="true" field="storageDevice" id="f_com_eg_egmedia_bizapp_model_ServiceItem_storageDevice" items="${storagedeviceenums}" path="/storagedeviceenums" required="false" z="user-managed"/>
<field:select_optional disableFormBinding="true" field="workOrder" id="f_com_eg_egmedia_bizapp_model_ServiceItem_workOrder" itemValue="id" items="${workorders}" path="/workorders" required="false" z="user-managed"/>
<field:select_optional disableFormBinding="true" field="serviceOffering" id="f_com_eg_egmedia_bizapp_model_ServiceItem_serviceOffering" itemValue="id" items="${serviceofferings}" path="/serviceofferings" required="false" z="user-managed"/>
</form:find_without_validation>
</div>
My <field:select_optional> tag is just the default <field:select> tag with an extra <option value="" />
Find
select.tagxin your project and inside this file find the following line:Inside decorators
widgetAttrsadd a new option:So that the edited line looks like:
After this modification the
requiredattribute infield:selecttag will work well.