svn commit: r1096293 - in /ofbiz/trunk: applications/product/widget/catalog/ProductForms.xml framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java framework/widget/templates/htmlFormMacroLibrary.ftl

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1096293 - in /ofbiz/trunk: applications/product/widget/catalog/ProductForms.xml framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java framework/widget/templates/htmlFormMacroLibrary.ftl

jleroux@apache.org
Author: jleroux
Date: Sun Apr 24 09:48:59 2011
New Revision: 1096293

URL: http://svn.apache.org/viewvc?rev=1096293&view=rev
Log:
A patch from Nicolas Malin "Enhanced way of displaying "missing/incorrect fields"" https://issues.apache.org/jira/browse/OFBIZ-2132

Initial demand by Michael Pätzold
At the moment we concentrate on increasing the usability of the backend application. One thing we recognized is the way form errors are reported to the users. Now it's done by showing a list of entity fields, that are required. A more common approach would be to highlight the form controls, that were not/wrongly filled. Was/Is there any task related to that or something similar?

Nicolas's solution
With integration of JQuery and validate function integrate by Sascha, I extend the Form renderer to apply required class and alert the form when she submitted to pass by JQuery validate function.

JLR: I have added a required field to InternalName field in Edit Product Form. Threre a re maybe other cases like that which should be improved...

Modified:
    ofbiz/trunk/applications/product/widget/catalog/ProductForms.xml
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
    ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl

Modified: ofbiz/trunk/applications/product/widget/catalog/ProductForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/widget/catalog/ProductForms.xml?rev=1096293&r1=1096292&r2=1096293&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/widget/catalog/ProductForms.xml (original)
+++ ofbiz/trunk/applications/product/widget/catalog/ProductForms.xml Sun Apr 24 09:48:59 2011
@@ -47,7 +47,7 @@ under the License.
                 <parameter param-name="productId"/>
             </hyperlink>
         </field>
-        
+
         <field name="internalName" sort-field="true"><display/></field>
         <field name="brandName" sort-field="true"><display/></field>
         <field name="productName" sort-field="true"><display/></field>
@@ -96,7 +96,7 @@ under the License.
             </drop-down>
         </field>
 
-        <field position="1" name="internalName" title="${uiLabelMap.ProductInternalName}"><text size="30" maxlength="255"/></field>
+        <field position="1" name="internalName" title="${uiLabelMap.ProductInternalName}" required-field="true"><text size="30" maxlength="255"/></field>
         <field position="2" name="brandName" title="${uiLabelMap.ProductBrandName}" ><text size="30" maxlength="60"/></field>
         <field name="manufacturerPartyId" title="${uiLabelMap.ProductOemPartyId}" ><text size="20" maxlength="20"/></field>
         <field name="comments" title="${uiLabelMap.CommonComments}"><text size="60" maxlength="250"/></field>
@@ -2032,7 +2032,7 @@ under the License.
         </field>
         <field name="submitButton" title="${uiLabelMap.CommonAdd}" widget-style="smallSubmit"><submit button-type="button"/></field>
     </form>
-    
+
     <form name="ListBestProduct" type="list" paginate="false" list-name="bestSellingProducts" view-size="5"
             header-row-style="header-row" odd-row-style="alternate-row" default-table-style="basic-table hover-bar">
         <field name="productName" title="${uiLabelMap.ProductName}"><display description="${productName}"/></field>
@@ -2066,7 +2066,7 @@ under the License.
         header-row-style="header-row" default-table-style="basic-table">
         <auto-fields-service service-name="addPartyToProduct"/>
         <field name="productId"><hidden/></field>
-        <field name="partyId"><lookup target-form-name="LookupPartyName"/></field>        
+        <field name="partyId"><lookup target-form-name="LookupPartyName"/></field>
         <field name="roleTypeId">
             <drop-down allow-empty="false">
                 <entity-options entity-name="RoleType" description="${description}" key-field-name="roleTypeId">

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java?rev=1096293&r1=1096292&r2=1096293&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java Sun Apr 24 09:48:59 2011
@@ -352,6 +352,14 @@ public class MacroFormRenderer implement
         String id = modelFormField.getCurrentContainerId(context);
         String clientAutocomplete = "false";
 
+        //check for required field style on single forms
+        if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
+            String requiredStyle = modelFormField.getRequiredFieldStyle();
+            if (UtilValidate.isEmpty(requiredStyle)) requiredStyle = "required";            
+            if (UtilValidate.isEmpty(className)) className = requiredStyle;
+            else className = requiredStyle + " " + className;
+        }
+        
         List<ModelForm.UpdateArea> updateAreas = modelFormField.getOnChangeUpdateAreas();
         boolean ajaxEnabled = updateAreas != null && this.javaScriptEnabled;
         if (!textField.getClientAutocompleteField() || ajaxEnabled) {
@@ -425,6 +433,15 @@ public class MacroFormRenderer implement
                 alert = "true";
             }
         }
+        
+        //check for required field style on single forms
+        if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
+            String requiredStyle = modelFormField.getRequiredFieldStyle();
+            if (UtilValidate.isEmpty(requiredStyle)) requiredStyle = "required";            
+            if (UtilValidate.isEmpty(className)) className = requiredStyle;
+            else className = requiredStyle + " " + className;
+        }
+        
         String visualEditorEnable = "";
         String buttons = "";
         if (textareaField.getVisualEditorEnable()) {
@@ -618,6 +635,15 @@ public class MacroFormRenderer implement
                 ampmName = UtilHttp.makeCompositeParam(paramName, "ampm");
             }
         }
+        
+        //check for required field style on single forms
+        if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
+            String requiredStyle = modelFormField.getRequiredFieldStyle();
+            if (UtilValidate.isEmpty(requiredStyle)) requiredStyle = "required";            
+            if (UtilValidate.isEmpty(className)) className = requiredStyle;
+            else className = requiredStyle + " " + className;
+        }
+        
         String mask = dateTimeField.getMask();
         if ("Y".equals(mask)) {
             if ("date".equals(dateTimeField.getType())) {
@@ -745,6 +771,14 @@ public class MacroFormRenderer implement
             }
         }
 
+        //check for required field style on single forms
+        if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
+            String requiredStyle = modelFormField.getRequiredFieldStyle();
+            if (UtilValidate.isEmpty(requiredStyle)) requiredStyle = "required";            
+            if (UtilValidate.isEmpty(className)) className = requiredStyle;
+            else className = requiredStyle + " " + className;
+        }
+        
         String currentDescription = null;
         if (UtilValidate.isNotEmpty(currentValue)) {
             for (ModelFormField.OptionValue optionValue : allOptionValues) {
@@ -1341,12 +1375,24 @@ public class MacroFormRenderer implement
     public void renderFormClose(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException {
         String focusFieldName = modelForm.getfocusFieldName();
         String formName = modelForm.getCurrentFormName(context);
+        String containerId = modelForm.getCurrentContainerId(context);
+        String hasRequiredField = "";
+        for (ModelFormField formField : modelForm.getFieldList()) {
+            if (formField.getRequiredField()) {
+                hasRequiredField = "Y";
+                break;
+            }
+        }
         StringWriter sr = new StringWriter();
         sr.append("<@renderFormClose ");
         sr.append(" focusFieldName=\"");
         sr.append(focusFieldName);
         sr.append("\" formName=\"");
         sr.append(formName);
+        sr.append("\" containerId=\"");
+        sr.append(containerId);
+        sr.append("\" hasRequiredField=\"");
+        sr.append(hasRequiredField);
         sr.append("\" />");
         executeMacro(writer, sr.toString());
         renderEndingBoundaryComment(writer, "Form Widget - Form Element", modelForm);
@@ -1999,6 +2045,14 @@ public class MacroFormRenderer implement
                 alert = "true";
             }
         }
+        
+        //check for required field style on single forms
+        if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
+            String requiredStyle = modelFormField.getRequiredFieldStyle();
+            if (UtilValidate.isEmpty(requiredStyle)) requiredStyle = "required";            
+            if (UtilValidate.isEmpty(className)) className = requiredStyle;
+            else className = requiredStyle + " " + className;
+        }
 
         String name = modelFormField.getParameterName(context);
         String value = modelFormField.getEntry(context, lookupField.getDefaultValue(context));

Modified: ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl?rev=1096293&r1=1096292&r2=1096293&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl (original)
+++ ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Sun Apr 24 09:48:59 2011
@@ -297,7 +297,7 @@ ${item.description}</span>
         <input type="hidden" name="_useRowSubmit" value="Y"/>
     </#if>
 </#macro>
-<#macro renderFormClose focusFieldName formName>
+<#macro renderFormClose focusFieldName formName containerId hasRequiredField>
     </form><#lt/>
     <#if focusFieldName?has_content>
         <script language="JavaScript" type="text/javascript">
@@ -310,6 +310,16 @@ ${item.description}</span>
           }
         </script><#lt/>
     </#if>
+    <#if containerId?has_content && hasRequiredField?has_content>
+      <script type="text/javascript">
+          jQuery("#${containerId}").validate({
+             submitHandler:
+                 function(form) {
+                 form.submit();
+             }
+          });
+      </script>
+    </#if>
 </#macro>
 <#macro renderMultiFormClose>
     </form><#lt/>