Fixed: Required field not working on upload type form
When trying to submit an upload form with empty required fields, the validation
is not blocked and the submit is made.
Thanks: Leila Mekika
@@ -250,7 +250,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";
@@ -322,6 +322,12 @@ 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();
@@ -486,7 +492,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";
@@ -633,7 +639,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";
@@ -1196,7 +1202,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;
@@ -2058,7 +2064,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";
@@ -2559,7 +2565,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";
