Skip to content

Commit

Permalink
Updating FFL fragments (#72)
Browse files Browse the repository at this point in the history
* Adding a checkbox set fragment that works with InputOption enums

* refactoring

* Refactoring

* cleanup

* null check

* codeql
  • Loading branch information
sree-cfa authored Feb 26, 2024
1 parent 17c2bcf commit 44cfd31
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 27 deletions.
31 changes: 31 additions & 0 deletions src/main/java/org/ilgcc/app/utils/GenderOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.ilgcc.app.utils;

public enum GenderOption implements InputOption {

MALE("general.inputs.male"),
FEMALE("general.inputs.female"),
NONBINARY("general.inputs.non-binary"),
TRANSGENDER("general.inputs.transgender"),
NO_ANSWER("general.inputs.prefer-not-to-answer");

private final String label;

GenderOption(String label) {
this.label = label;
}

@Override
public String getLabel() {
return label;
}

@Override
public String getValue() {
return this.name();
}

@Override
public String getHelpText() {
return null;
}
}
11 changes: 11 additions & 0 deletions src/main/java/org/ilgcc/app/utils/InputOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.ilgcc.app.utils;


public interface InputOption {

String getLabel();

String getValue();

String getHelpText();
}
35 changes: 35 additions & 0 deletions src/main/java/org/ilgcc/app/utils/RaceEthnicityOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.ilgcc.app.utils;

public enum RaceEthnicityOption implements InputOption {

ASIAN("general.inputs.race-ethnicity.asian"),
BLACK("general.inputs.race-ethnicity.black-or-african-american"),
HISPANIC("general.inputs.race-ethnicity.hispanic-latino-or-spanish"),
MIDDLE_EASTERN("general.inputs.race-ethnicity.middle-eastern-or-north-african"),
NATIVE_AMERICAN("general.inputs.race-ethnicity.native-american-or-alaska-native"),
NATIVE_HAWAIIAN("general.inputs.race-ethnicity.native-hawaiian-or-pacific-islander"),
WHITE("general.inputs.race-ethnicity.white"),
OTHER("general.inputs.race-ethnicity.other");

private final String label;

RaceEthnicityOption(String label) {
this.label = label;
}

@Override
public String getLabel() {
return label;
}

@Override
public String getValue() {
return this.name();
}

@Override
public String getHelpText() {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<th:block
th:fragment="checkboxFieldset"
th:with="
hasHelpText=${!#strings.isEmpty(fieldsetHelpText)},
hasLabel=${!#strings.isEmpty(label)},
hasAriaLabel=${!#strings.isEmpty(ariaLabel)},
hasOptions=${options != null},
hasContent=${!hasOptions},
hasError=${
errorMessages != null &&
errorMessages.get(inputName) != null &&
(#arrays.length(errorMessages.get(inputName)) > 0) }"
th:assert="
${!#strings.isEmpty(inputName)},
${hasLabel || hasAriaLabel},
${hasContent || hasOptions}">
<div th:class="'form-group' + ${(hasError ? ' form-group--error' : '')}">
<fieldset th:attr="
aria-describedby=${hasHelpText ? inputName + '-help-text' : ''},
aria-labelledby=${hasAriaLabel ? ariaLabel : ''}">
<legend class="form-question"
th:if="${hasLabel}"
th:id="${inputName + '-legend'}"
th:inline="text">
[[${label}]]
<p class="text--help spacing-below-0 text--normal"
th:if="${hasHelpText}"
th:id="${inputName + '-help-text'}"
th:text="${fieldsetHelpText}"></p>
</legend>
<input type="hidden" th:id="${inputName} + 'Hidden'" th:name="${inputName} + '[]'" value="">
<th:block th:if="${hasContent}">
<th:block th:replace="${content}"/>
</th:block>
<th:block th:if="${hasOptions}">
<th:block th:each="option : ${options}">
<th:block th:replace="~{fragments/inputs/checkboxInSet ::
checkboxInSet(inputName=${inputName},
value=${option.getValue()},
label=${#strings.isEmpty(option.getLabel()) ? null : #messages.msg(option.getLabel())},
checkboxHelpText=${#strings.isEmpty(option.getHelpText()) ? null : #messages.msg(option.getHelpText())})}"/>
</th:block>
</th:block>
<th:block
th:replace="~{fragments/inputError :: validationError(inputName=${inputName})}"></th:block>
</fieldset>
</div>
</th:block>
47 changes: 47 additions & 0 deletions src/main/resources/templates/fragments/inputs/radioFieldset.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<th:block
th:fragment="radioFieldset"
th:with="
hasHelpText=${!#strings.isEmpty(fieldsetHelpText)},
hasLabel=${!#strings.isEmpty(label)},
hasAriaLabel=${!#strings.isEmpty(ariaLabel)},
hasOptions=${options != null},
hasContent=${!hasOptions},
hasError=${
errorMessages != null &&
errorMessages.get(inputName) != null &&
(#arrays.length(errorMessages.get(inputName)) > 0) }"
th:assert="
${!#strings.isEmpty(inputName)},
${hasLabel || hasAriaLabel},
${hasContent || hasOptions}">
<div th:class="'form-group' + ${(hasError ? ' form-group--error' : '')}">
<fieldset th:attr="
aria-describedby=${hasHelpText ? inputName + '-help-text' : ''},
aria-labelledby=${hasAriaLabel ? ariaLabel : ''}">
<legend class="form-question"
th:id="${inputName + '-legend'}"
th:inline="text">
[[${label}]]
<p class="text--help spacing-below-0 text--normal"
th:if="${hasHelpText}"
th:id="${inputName + '-help-text'}"
th:text="${fieldsetHelpText}"></p>
</legend>
<input type="hidden" th:id="${inputName} + 'Hidden'" th:name="${inputName}" value="">
<th:block th:if="${hasContent}">
<th:block th:replace="${content}"/>
</th:block>
<th:block th:if="${hasOptions}">
<th:block th:each="option : ${options}">
<th:block th:replace="~{fragments/inputs/radio ::
radio(inputName=${inputName},
value=${option.getValue()},
label=${#strings.isEmpty(option.getLabel()) ? null : #messages.msg(option.getLabel())},
radioHelpText=${#strings.isEmpty(option.getHelpText()) ? null : #messages.msg(option.getHelpText())})}"/>
</th:block>
</th:block>
</fieldset>
<th:block
th:replace="~{fragments/inputError :: validationError(inputName=${inputName})}"></th:block>
</div>
</th:block>
37 changes: 10 additions & 27 deletions src/main/resources/templates/gcc/children-ccap-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@
<th:block
th:replace="~{fragments/cardHeader :: cardHeader(header=#{children-ccap-info.header(${fieldData.get('childFirstName')})}, subtext=#{children-ccap-info.subheader})}"/>
<th:block th:replace="~{fragments/form :: form(action=${formAction}, content=~{::formContent})}">
<th:block th:ref="formContent">
<th:block th:ref="formContent"
th:with="
genderOptions=${T(org.ilgcc.app.utils.GenderOption).values()},
raceEthnicityOptions=${T(org.ilgcc.app.utils.RaceEthnicityOption).values()}">
<div class="form-card__content">
<th:block th:replace="~{'fragments/inputs/checkboxFieldset' ::
<th:block th:replace="~{fragments/inputs/checkboxFieldset ::
checkboxFieldset(inputName='childGender',
label=#{children-ccap-info.gender-question},
content=~{::genderContent})}">
<th:block th:ref="genderContent">
<th:block th:replace="~{fragments/inputs/checkboxInSet :: checkboxInSet(inputName='childGender', value='MALE', label=#{general.inputs.male})}"/>
<th:block th:replace="~{fragments/inputs/checkboxInSet :: checkboxInSet(inputName='childGender', value='FEMALE', label=#{general.inputs.female})}"/>
<th:block th:replace="~{fragments/inputs/checkboxInSet :: checkboxInSet(inputName='childGender', value='NONBINARY', label=#{general.inputs.non-binary})}"/>
<th:block th:replace="~{fragments/inputs/checkboxInSet :: checkboxInSet(inputName='childGender', value='TRANSGENDER', label=#{general.inputs.transgender})}"/>
<th:block th:replace="~{fragments/inputs/checkboxInSet :: checkboxInSet(inputName='childGender', value='NO_ANSWER', label=#{general.inputs.prefer-not-to-answer})}"/>
</th:block>
</th:block>
label=#{children-ccap-info.gender-question},
options=${genderOptions})}"/>

<th:block th:replace="~{fragments/inputs/radioFieldset ::
radioFieldset(inputName='childHasDisability',
Expand Down Expand Up @@ -59,22 +54,10 @@
</th:block>
</th:block>

<th:block th:replace="~{'fragments/inputs/checkboxFieldset' ::
<th:block th:replace="~{fragments/inputs/checkboxFieldset ::
checkboxFieldset(inputName='childRaceEthnicity',
label=#{children-ccap-info.race-ethnicity-question},
fieldsetHelpText=#{children-ccap-info.race-ethnicity-help-text},
content=~{::raceEthnicityContent})}">
<th:block th:ref="raceEthnicityContent">
<th:block th:replace="~{fragments/inputs/checkboxInSet :: checkboxInSet(inputName='childRaceEthnicity', value='ASIAN', label=#{general.inputs.race-ethnicity.asian})}"/>
<th:block th:replace="~{fragments/inputs/checkboxInSet :: checkboxInSet(inputName='childRaceEthnicity', value='BLACK', label=#{general.inputs.race-ethnicity.black-or-african-american})}"/>
<th:block th:replace="~{fragments/inputs/checkboxInSet :: checkboxInSet(inputName='childRaceEthnicity', value='HISPANIC', label=#{general.inputs.race-ethnicity.hispanic-latino-or-spanish})}"/>
<th:block th:replace="~{fragments/inputs/checkboxInSet :: checkboxInSet(inputName='childRaceEthnicity', value='MIDDLE_EASTERN', label=#{general.inputs.race-ethnicity.middle-eastern-or-north-african})}"/>
<th:block th:replace="~{fragments/inputs/checkboxInSet :: checkboxInSet(inputName='childRaceEthnicity', value='NATIVE_AMERICAN', label=#{general.inputs.race-ethnicity.native-american-or-alaska-native})}"/>
<th:block th:replace="~{fragments/inputs/checkboxInSet :: checkboxInSet(inputName='childRaceEthnicity', value='NATIVE_HAWAIIAN', label=#{general.inputs.race-ethnicity.native-hawaiian-or-pacific-islander})}"/>
<th:block th:replace="~{fragments/inputs/checkboxInSet :: checkboxInSet(inputName='childRaceEthnicity', value='WHITE', label=#{general.inputs.race-ethnicity.white})}"/>
<th:block th:replace="~{fragments/inputs/checkboxInSet :: checkboxInSet(inputName='childRaceEthnicity', value='other', label=#{general.inputs.race-ethnicity.other})}"/>
</th:block>
</th:block>
label=#{children-ccap-info.race-ethnicity-question},
options=${raceEthnicityOptions})}"/>
</div>
<div class="form-card__footer">
<th:block th:replace="~{fragments/inputs/submitButton :: submitButton(text=#{general.inputs.continue})}"/>
Expand Down

0 comments on commit 44cfd31

Please sign in to comment.