This is an automated email from the ASF dual-hosted git repository. jleroux pushed a commit to branch release18.12 in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/release18.12 by this push: new e539734b75 Fixed: Required field not working on upload type form (OFBIZ-12619) e539734b75 is described below commit e539734b753f37c990a38a2271aec0fdfef88528 Author: Jacques Le Roux <jacques.le.r...@les7arts.com> AuthorDate: Sat May 21 10:35:11 2022 +0200 Fixed: Required field not working on upload type form (OFBIZ-12619) When trying to submit an upload form with empty required fields, the validation is not blocked and the submit is made. Thanks: Leila Mekika Conflicts handled by hand --- .../widget/renderer/macro/MacroFormRenderer.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java index 01a517df9d..0884a5324a 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java @@ -460,7 +460,7 @@ public final class MacroFormRenderer implements FormStringRenderer { } } //check for required field style on single forms - if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) { + if (shouldApplyRequiredField(modelFormField)) { String requiredStyle = modelFormField.getRequiredFieldStyle(); if (UtilValidate.isEmpty(requiredStyle)) { requiredStyle = "required"; @@ -529,6 +529,13 @@ public final class MacroFormRenderer implements FormStringRenderer { this.appendTooltip(writer, context, modelFormField); } + private boolean shouldApplyRequiredField(ModelFormField modelFormField) { + return ("single".equals(modelFormField.getModelForm().getType()) || + "upload".equals(modelFormField.getModelForm().getType())) + && modelFormField.getRequiredField(); + } + + @Override public void renderDateTimeField(Appendable writer, Map<String, Object> context, DateTimeField dateTimeField) throws IOException { ModelFormField modelFormField = dateTimeField.getModelFormField(); String paramName = modelFormField.getParameterName(context); @@ -681,7 +688,7 @@ public final class MacroFormRenderer implements FormStringRenderer { } } //check for required field style on single forms - if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) { + if (shouldApplyRequiredField(modelFormField)) { String requiredStyle = modelFormField.getRequiredFieldStyle(); if (UtilValidate.isEmpty(requiredStyle)) { requiredStyle = "required"; @@ -817,7 +824,7 @@ public final class MacroFormRenderer implements FormStringRenderer { } } //check for required field style on single forms - if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) { + if (shouldApplyRequiredField(modelFormField)) { String requiredStyle = modelFormField.getRequiredFieldStyle(); if (UtilValidate.isEmpty(requiredStyle)) { requiredStyle = "required"; @@ -1339,7 +1346,7 @@ public final class MacroFormRenderer implements FormStringRenderer { } if (!sb.toString().isEmpty()) { //check for required field style on single forms - if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) { + if (shouldApplyRequiredField(modelFormField)) { String requiredStyle = modelFormField.getRequiredFieldStyle(); if (UtilValidate.isNotEmpty(requiredStyle)) { style = requiredStyle; @@ -2145,7 +2152,7 @@ public final class MacroFormRenderer implements FormStringRenderer { } } //check for required field style on single forms - if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) { + if (shouldApplyRequiredField(modelFormField)) { String requiredStyle = modelFormField.getRequiredFieldStyle(); if (UtilValidate.isEmpty(requiredStyle)) { requiredStyle = "required"; @@ -2634,7 +2641,7 @@ public final class MacroFormRenderer implements FormStringRenderer { } //check for required field style on single forms - if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) { + if (shouldApplyRequiredField(modelFormField)) { String requiredStyle = modelFormField.getRequiredFieldStyle(); if (UtilValidate.isEmpty(requiredStyle)) { requiredStyle = "required";