From cc095d483801f4a48ccce780100a68efdcdf65e7 Mon Sep 17 00:00:00 2001
From: spokenbird
Date: Thu, 1 Feb 2024 16:50:08 -0800
Subject: [PATCH 01/41] Automatically indicate required text fields
---
.../formflow/library/ScreenController.java | 2 ++
.../formflow/library/ValidationService.java | 27 ++++++++++++++++---
.../form-flow/0.0.1/css/libraryStyles.css | 5 ++++
.../templates/fragments/inputs/text.html | 9 +++++--
4 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/src/main/java/formflow/library/ScreenController.java b/src/main/java/formflow/library/ScreenController.java
index ec7a6e329..7dd8e38e1 100644
--- a/src/main/java/formflow/library/ScreenController.java
+++ b/src/main/java/formflow/library/ScreenController.java
@@ -868,6 +868,8 @@ private Map createModel(String flow, String screen, HttpSession
if (RequestContextUtils.getInputFlashMap(request) != null) {
model.put("lockedSubmissionMessage", RequestContextUtils.getInputFlashMap(request).get("lockedSubmissionMessage"));
}
+
+ model.put("requiredInputs", ValidationService.getRequiredInputs(flow));
return model;
}
diff --git a/src/main/java/formflow/library/ValidationService.java b/src/main/java/formflow/library/ValidationService.java
index 1fbdad732..f573e6e52 100644
--- a/src/main/java/formflow/library/ValidationService.java
+++ b/src/main/java/formflow/library/ValidationService.java
@@ -9,6 +9,7 @@
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -38,8 +39,8 @@ public class ValidationService {
private final Validator validator;
private final ActionManager actionManager;
- private final String inputConfigPath;
- private final List requiredAnnotationsList = List.of(
+ private static String inputConfigPath;
+ private static final List requiredAnnotationsList = List.of(
NotNull.class.getName(),
NotEmpty.class.getName(),
NotBlank.class.getName()
@@ -56,7 +57,7 @@ public ValidationService(Validator validator, ActionManager actionManager,
@Value("${form-flow.inputs: 'formflow.library.inputs.'}") String inputConfigPath) {
this.validator = validator;
this.actionManager = actionManager;
- this.inputConfigPath = inputConfigPath;
+ ValidationService.inputConfigPath = inputConfigPath;
}
/**
@@ -158,4 +159,24 @@ private Map> performFieldLevelValidation(String flowName, F
return validationMessages;
}
+
+ public static List getRequiredInputs(String flowName) {
+ Class> flowClass;
+ List requiredInputs = new ArrayList<>();
+
+ try {
+ flowClass = Class.forName(inputConfigPath + StringUtils.capitalize(flowName));
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException(e);
+ }
+
+ Field[] declaredFields = flowClass.getDeclaredFields();
+ for (Field field : declaredFields) {
+ if (Arrays.stream(field.getAnnotations())
+ .anyMatch(annotation -> requiredAnnotationsList.contains(annotation.annotationType().getName()))) {
+ requiredInputs.add(field.getName());
+ }
+ }
+ return requiredInputs;
+ }
}
diff --git a/src/main/resources/META-INF/resources/webjars/form-flow/0.0.1/css/libraryStyles.css b/src/main/resources/META-INF/resources/webjars/form-flow/0.0.1/css/libraryStyles.css
index 1f68c7db0..e840d580c 100644
--- a/src/main/resources/META-INF/resources/webjars/form-flow/0.0.1/css/libraryStyles.css
+++ b/src/main/resources/META-INF/resources/webjars/form-flow/0.0.1/css/libraryStyles.css
@@ -741,3 +741,8 @@ body,
display: inline-flex;
align-items: center;
}
+
+.required-input {
+ color: #a72f10;
+ margin-left: 0.5rem;
+}
diff --git a/src/main/resources/templates/fragments/inputs/text.html b/src/main/resources/templates/fragments/inputs/text.html
index b21e869c4..889015f78 100644
--- a/src/main/resources/templates/fragments/inputs/text.html
+++ b/src/main/resources/templates/fragments/inputs/text.html
@@ -4,13 +4,17 @@
hasHelpText=${!#strings.isEmpty(helpText)},
hasLabel=${!#strings.isEmpty(label)},
hasAriaLabel=${!#strings.isEmpty(ariaLabel)},
- hasError=${
+ isRequiredInput=${requiredInputs.contains(inputName)},
+ hasError=${
errorMessages != null &&
errorMessages.get(inputName) != null &&
(#arrays.length(errorMessages.get(inputName)) > 0) }"
th:assert="${!#strings.isEmpty(inputName)}, ${hasLabel || hasAriaLabel}">
-
+
Date: Fri, 2 Feb 2024 16:37:16 -0800
Subject: [PATCH 02/41] Adds error handling changes for the date input
---
.../form-flow/0.0.1/css/libraryStyles.css | 1 -
.../resources/templates/fragments/form.html | 1 +
.../templates/fragments/inputs/date.html | 34 ++++++++++++++-----
.../templates/fragments/inputs/text.html | 8 ++---
4 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/src/main/resources/META-INF/resources/webjars/form-flow/0.0.1/css/libraryStyles.css b/src/main/resources/META-INF/resources/webjars/form-flow/0.0.1/css/libraryStyles.css
index e840d580c..2b2fc3b23 100644
--- a/src/main/resources/META-INF/resources/webjars/form-flow/0.0.1/css/libraryStyles.css
+++ b/src/main/resources/META-INF/resources/webjars/form-flow/0.0.1/css/libraryStyles.css
@@ -744,5 +744,4 @@ body,
.required-input {
color: #a72f10;
- margin-left: 0.5rem;
}
diff --git a/src/main/resources/templates/fragments/form.html b/src/main/resources/templates/fragments/form.html
index 6e9b66952..ae52b5a25 100644
--- a/src/main/resources/templates/fragments/form.html
+++ b/src/main/resources/templates/fragments/form.html
@@ -3,6 +3,7 @@
th:action="@{${action}}"
th:enctype="${enctype}"
th:id="${formId}"
+ novalidate="true"
autocomplete="off"
method="post">
diff --git a/src/main/resources/templates/fragments/inputs/date.html b/src/main/resources/templates/fragments/inputs/date.html
index d444826f5..83f0dad3b 100644
--- a/src/main/resources/templates/fragments/inputs/date.html
+++ b/src/main/resources/templates/fragments/inputs/date.html
@@ -3,6 +3,7 @@
th:with="
hasLabel=${!#strings.isEmpty(label)},
hasAriaLabel=${!#strings.isEmpty(ariaLabel)},
+ isRequiredInput=${requiredInputs.contains(inputName + 'Month') || requiredInputs.contains(inputName + 'Day') || requiredInputs.contains(inputName + 'Year')},
hasErrorMonth=${errorMessages != null && !#arrays.isEmpty(errorMessages.get(inputName + 'Month'))},
hasErrorDay=${errorMessages != null && !#arrays.isEmpty(errorMessages.get(inputName + 'Day'))},
hasErrorYear=${errorMessages != null && !#arrays.isEmpty(errorMessages.get(inputName + 'Year'))},
@@ -10,7 +11,11 @@
th:assert="${hasLabel || hasAriaLabel}">
-
-
-
-
+
+
+
+
diff --git a/src/main/resources/templates/fragments/inputs/text.html b/src/main/resources/templates/fragments/inputs/text.html
index 889015f78..62c13f237 100644
--- a/src/main/resources/templates/fragments/inputs/text.html
+++ b/src/main/resources/templates/fragments/inputs/text.html
@@ -19,6 +19,8 @@
th:if="${hasHelpText}"
th:id="${inputName + '-help-text'}"
th:text="${helpText}">
+
-
\ No newline at end of file
From d5140ac5ce3d4eb528528916365cbd4065ab00a9 Mon Sep 17 00:00:00 2001
From: spokenbird
Date: Mon, 5 Feb 2024 16:02:37 -0800
Subject: [PATCH 03/41] Update money input to show required attribute
---
src/main/resources/templates/fragments/form.html | 1 -
.../resources/templates/fragments/inputs/money.html | 13 +++++++++----
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/main/resources/templates/fragments/form.html b/src/main/resources/templates/fragments/form.html
index ae52b5a25..6e9b66952 100644
--- a/src/main/resources/templates/fragments/form.html
+++ b/src/main/resources/templates/fragments/form.html
@@ -3,7 +3,6 @@
th:action="@{${action}}"
th:enctype="${enctype}"
th:id="${formId}"
- novalidate="true"
autocomplete="off"
method="post">
diff --git a/src/main/resources/templates/fragments/inputs/money.html b/src/main/resources/templates/fragments/inputs/money.html
index e1f8b2bfb..38f43d2aa 100644
--- a/src/main/resources/templates/fragments/inputs/money.html
+++ b/src/main/resources/templates/fragments/inputs/money.html
@@ -4,17 +4,23 @@
hasHelpText=${!#strings.isEmpty(helpText)},
hasLabel=${!#strings.isEmpty(label)},
hasAriaLabel=${!#strings.isEmpty(ariaLabel)},
+ isRequiredInput=${requiredInputs.contains(inputName)},
hasError=${
errorMessages != null &&
errorMessages.get(inputName) != null &&
(#arrays.length(errorMessages.get(inputName)) > 0) }"
th:assert="${!#strings.isEmpty(inputName)}, ${hasLabel || hasAriaLabel}">
From 7759557231baf8272bd6586708f904049a6c0f8e Mon Sep 17 00:00:00 2001
From: spokenbird
Date: Mon, 5 Feb 2024 16:23:01 -0800
Subject: [PATCH 04/41] Update number, phone and ssn inputs to show required
attribute
---
.../templates/fragments/inputs/number.html | 13 +++++++++----
.../templates/fragments/inputs/phone.html | 13 +++++++++----
.../resources/templates/fragments/inputs/ssn.html | 15 +++++++++++----
.../templates/fragments/inputs/text.html | 2 +-
4 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/src/main/resources/templates/fragments/inputs/number.html b/src/main/resources/templates/fragments/inputs/number.html
index a7ef0f4d9..2cdd5d4af 100644
--- a/src/main/resources/templates/fragments/inputs/number.html
+++ b/src/main/resources/templates/fragments/inputs/number.html
@@ -6,17 +6,23 @@
hasPattern=${!#strings.isEmpty(pattern)},
hasLabel=${!#strings.isEmpty(label)},
hasAriaLabel=${!#strings.isEmpty(ariaLabel)},
+ isRequiredInput=${requiredInputs.contains(inputName)},
hasError=${
errorMessages != null &&
errorMessages.get(inputName) != null &&
(#arrays.length(errorMessages.get(inputName)) > 0) }"
th:assert="${!#strings.isEmpty(inputName)}, ${hasLabel || hasAriaLabel}">
diff --git a/src/main/resources/templates/fragments/inputs/phone.html b/src/main/resources/templates/fragments/inputs/phone.html
index 971e8fca7..807fb392a 100644
--- a/src/main/resources/templates/fragments/inputs/phone.html
+++ b/src/main/resources/templates/fragments/inputs/phone.html
@@ -4,17 +4,23 @@
hasHelpText=${!#strings.isEmpty(helpText)},
hasLabel=${!#strings.isEmpty(label)},
hasAriaLabel=${!#strings.isEmpty(ariaLabel)},
+ isRequiredInput=${requiredInputs.contains(inputName)},
hasError=${
errorMessages != null &&
errorMessages.get(inputName) != null &&
(#arrays.length(errorMessages.get(inputName)) > 0) }"
th:assert="${!#strings.isEmpty(inputName)}, ${hasLabel || hasAriaLabel}">
\ No newline at end of file
diff --git a/src/main/resources/templates/fragments/inputs/ssn.html b/src/main/resources/templates/fragments/inputs/ssn.html
index 99091d070..8ab7626bc 100644
--- a/src/main/resources/templates/fragments/inputs/ssn.html
+++ b/src/main/resources/templates/fragments/inputs/ssn.html
@@ -4,17 +4,25 @@
hasHelpText=${!#strings.isEmpty(helpText)},
hasLabel=${!#strings.isEmpty(label)},
hasAriaLabel=${!#strings.isEmpty(ariaLabel)},
+ isRequiredInput=${requiredInputs.contains(inputName)},
hasError=${
errorMessages != null &&
errorMessages.get(inputName) != null &&
(#arrays.length(errorMessages.get(inputName)) > 0) }"
th:assert="${!#strings.isEmpty(inputName)}, ${hasLabel || hasAriaLabel}">
\ No newline at end of file
diff --git a/src/main/resources/templates/fragments/inputs/text.html b/src/main/resources/templates/fragments/inputs/text.html
index 62c13f237..f11fdac12 100644
--- a/src/main/resources/templates/fragments/inputs/text.html
+++ b/src/main/resources/templates/fragments/inputs/text.html
@@ -5,7 +5,7 @@
hasLabel=${!#strings.isEmpty(label)},
hasAriaLabel=${!#strings.isEmpty(ariaLabel)},
isRequiredInput=${requiredInputs.contains(inputName)},
- hasError=${
+ hasError=${
errorMessages != null &&
errorMessages.get(inputName) != null &&
(#arrays.length(errorMessages.get(inputName)) > 0) }"
From 7f14ae9cf541a945eca470c039ec3b804e05447a Mon Sep 17 00:00:00 2001
From: spokenbird
Date: Tue, 13 Feb 2024 15:10:51 -0800
Subject: [PATCH 05/41] Update select input to show required attribute
---
.../resources/templates/fragments/inputs/select.html | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/main/resources/templates/fragments/inputs/select.html b/src/main/resources/templates/fragments/inputs/select.html
index 86bb0e5a7..ff2f26549 100644
--- a/src/main/resources/templates/fragments/inputs/select.html
+++ b/src/main/resources/templates/fragments/inputs/select.html
@@ -4,6 +4,7 @@
hasHelpText=${!#strings.isEmpty(helpText)},
hasLabel=${!#strings.isEmpty(label)},
hasAriaLabel=${!#strings.isEmpty(ariaLabel)},
+ isRequiredInput=${requiredInputs.contains(inputName)},
hasError=${
errorMessages != null &&
errorMessages.get(inputName) != null &&
@@ -13,11 +14,16 @@
${hasLabel || hasAriaLabel},
${content != null}">
\ No newline at end of file
From be34480dbb3e1693f882c137e0d4bbb5032c6dee Mon Sep 17 00:00:00 2001
From: spokenbird
Date: Tue, 13 Feb 2024 15:58:54 -0800
Subject: [PATCH 06/41] Update radio input to show required attribute in
fieldset
---
src/main/resources/templates/fragments/inputs/radio.html | 1 +
.../templates/fragments/inputs/radioFieldset.html | 8 +++++---
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/main/resources/templates/fragments/inputs/radio.html b/src/main/resources/templates/fragments/inputs/radio.html
index 8893b2aea..0031be999 100644
--- a/src/main/resources/templates/fragments/inputs/radio.html
+++ b/src/main/resources/templates/fragments/inputs/radio.html
@@ -18,6 +18,7 @@
th:aria-disabled="${disabled}"
th:attr="
aria-invalid=${hasError},
+ aria-required=${isRequiredInput},
data-follow-up=${followUpId}">
- [[${label}]]
+
+ *
+
-
\ No newline at end of file
From 086265f6c63f24d33cdb69f244b45435929cd10e Mon Sep 17 00:00:00 2001
From: spokenbird
Date: Tue, 13 Feb 2024 17:16:46 -0800
Subject: [PATCH 07/41] Only render error element if errors are present and add
appropriate margin
---
.../webjars/form-flow/0.0.1/css/libraryStyles.css | 4 ++++
.../resources/templates/fragments/inputs/money.html | 1 +
.../resources/templates/fragments/inputs/number.html | 1 +
.../resources/templates/fragments/inputs/phone.html | 1 +
.../templates/fragments/inputs/radioFieldset.html | 1 +
.../resources/templates/fragments/inputs/select.html | 1 +
.../resources/templates/fragments/inputs/ssn.html | 3 +--
.../resources/templates/fragments/inputs/text.html | 1 +
.../templates/fragments/inputs/textArea.html | 12 +++++++++---
9 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/src/main/resources/META-INF/resources/webjars/form-flow/0.0.1/css/libraryStyles.css b/src/main/resources/META-INF/resources/webjars/form-flow/0.0.1/css/libraryStyles.css
index 2b2fc3b23..83ae92d8b 100644
--- a/src/main/resources/META-INF/resources/webjars/form-flow/0.0.1/css/libraryStyles.css
+++ b/src/main/resources/META-INF/resources/webjars/form-flow/0.0.1/css/libraryStyles.css
@@ -745,3 +745,7 @@ body,
.required-input {
color: #a72f10;
}
+
+.form-group .text--help+.text--error {
+ margin-top: -2.5rem;
+}
diff --git a/src/main/resources/templates/fragments/inputs/money.html b/src/main/resources/templates/fragments/inputs/money.html
index 38f43d2aa..afda45402 100644
--- a/src/main/resources/templates/fragments/inputs/money.html
+++ b/src/main/resources/templates/fragments/inputs/money.html
@@ -20,6 +20,7 @@
th:id="${inputName + '-help-text'}"
th:text="${helpText}">
$
diff --git a/src/main/resources/templates/fragments/inputs/number.html b/src/main/resources/templates/fragments/inputs/number.html
index 2cdd5d4af..ff31ac4ce 100644
--- a/src/main/resources/templates/fragments/inputs/number.html
+++ b/src/main/resources/templates/fragments/inputs/number.html
@@ -22,6 +22,7 @@
th:id="${inputName + '-help-text'}"
th:text="${helpText}">
diff --git a/src/main/resources/templates/fragments/inputs/select.html b/src/main/resources/templates/fragments/inputs/select.html
index ff2f26549..092f440b3 100644
--- a/src/main/resources/templates/fragments/inputs/select.html
+++ b/src/main/resources/templates/fragments/inputs/select.html
@@ -23,6 +23,7 @@
th:id="${inputName + '-help-text'}"
th:text="${helpText}">