Skip to content

Commit

Permalink
ensure form field has label and field optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
wildone committed Jun 21, 2024
1 parent 0bf1d82 commit afac6ef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ public class Field extends BaseFormComponent {
@Getter
protected String labelId = DEFAULT_ID;

@Getter
protected boolean labelHidden = true; //hidden untill we find it as a child

@Getter
protected String fieldId = DEFAULT_ID;

@Getter
protected boolean fieldHidden = true; //hidden untill we find it as a child


// authored flex toggle
@Inject
@Getter
Expand Down Expand Up @@ -90,9 +97,11 @@ protected void init() {
if (name.equals("label")) {
String id = child.getValueMap().get("id", "");
this.labelId = this.resource.getName() + (StringUtils.isNotEmpty(id) ? "-" + id : "");
this.labelHidden = false;
} else if (name.equals("field")) {
String id = child.getValueMap().get("id", "");
this.fieldId = this.resource.getName() + (StringUtils.isNotEmpty(id) ? "-" + id : "");
this.fieldHidden = false;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template data-sly-template.variant="${ @ model }">
<field id="${model.id}" class="${model.componentClassNames}">
<sly data-sly-resource="${'label' @ selectors=['id', model.labelId, 'for', model.fieldId, 'fid', model.parentFieldId]}"></sly>
<sly data-sly-resource="${'field' @ selectors=['id', model.fieldId, 'fid', model.parentFieldId]}"></sly>
<sly data-sly-test="${!model.labelHidden}" data-sly-resource="${'label' @ selectors=['id', model.labelId, 'for', model.fieldId, 'fid', model.parentFieldId]}"></sly>
<sly data-sly-test="${!model.fieldHidden}" data-sly-resource="${'field' @ selectors=['id', model.fieldId, 'fid', model.parentFieldId]}"></sly>
</field>
</template>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template data-sly-template.variant="${ @ model }">
<field id="${model.id}" class="${model.componentClassNames}">
<sly data-sly-resource="${'label' @ selectors=['id', model.labelId, 'for', model.fieldId, 'fid', model.parentFieldId]}"></sly>
<sly data-sly-resource="${'field' @ selectors=['id', model.fieldId, 'fid', model.parentFieldId]}"></sly>
<sly data-sly-test="${!model.labelHidden}" data-sly-resource="${'label' @ selectors=['id', model.labelId, 'for', model.fieldId, 'fid', model.parentFieldId]}"></sly>
<sly data-sly-test="${!model.fieldHidden}" data-sly-resource="${'field' @ selectors=['id', model.fieldId, 'fid', model.parentFieldId]}"></sly>
</field>
</template>

0 comments on commit afac6ef

Please sign in to comment.