Skip to content

UE: Supporting a new CRX property for multi select dropdown's default values #1454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private ReservedProperties() {
public static final String PN_PLACEHOLDER = "placeholder";
public static final String PN_READ_ONLY = "readOnly";
public static final String PN_DEFAULT_VALUE = "default";
public static final String PN_MULTI_DEFAULT_VALUES = "fd:multiDefaultValues";
public static final String PN_FORMAT = "format";
public static final String PN_DISPLAY_FORMAT = "displayFormat";
public static final String PN_EDIT_FORMAT = "editFormat";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public abstract class AbstractOptionsFieldImpl extends AbstractFieldImpl impleme
@Nullable
protected String[] enumNames;

/**
* Default for single and multivalued fields used the same 'default' crx property.
* This was not compatible with Universal Editor's Property Rail Configuration.
* Therefore, adding this property as an additional way of defining default values.
**/
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = ReservedProperties.PN_MULTI_DEFAULT_VALUES)
@Nullable
protected Object[] multiDefaultValues;

@Override
public boolean isEnforceEnum() {
return enforceEnum;
Expand Down Expand Up @@ -118,7 +127,9 @@ public String[] getEnumNames() {
public Object[] getDefault() {
Object[] typedDefaultValue = null;
try {
if (defaultValue != null) {
if (multiDefaultValues != null) {
typedDefaultValue = ComponentUtils.coerce(type, multiDefaultValues);
} else if (defaultValue != null) {
typedDefaultValue = ComponentUtils.coerce(type, defaultValue);
}
} catch (Exception exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class DropDownImplTest {
private static final String CONTENT_ROOT = "/content";
private static final String PATH_DROPDOWN_1 = CONTENT_ROOT + "/dropdown-1";
private static final String PATH_MULTISELECT_DROPDOWN = CONTENT_ROOT + "/multiselect-dropdown";
private static final String PATH_MULTISELECT_DROPDOWN_WITH_VARIANT_PROPERTY = CONTENT_ROOT + "/multiselect-dropdown-2";
private static final String PATH_DROPDOWN2 = CONTENT_ROOT + "/dropdown2";

private static final String PATH_DROPDOWN = CONTENT_ROOT + "/dropdown";
Expand Down Expand Up @@ -354,6 +355,12 @@ void testGetMultiSelectDefault() {
assertArrayEquals(new Long[] { 0L, 1L }, dropdown.getDefault());
}

@Test
void testGetMultiSelectDefault_WithDiffProperty() {
DropDown dropdown = Utils.getComponentUnderTest(PATH_MULTISELECT_DROPDOWN_WITH_VARIANT_PROPERTY, DropDown.class, context);
assertArrayEquals(new Long[] { 0L, 1L }, dropdown.getDefault());
}

@Test
void testGetMultiSelectDefault_InvalidType() throws IllegalAccessException {
DropDown dropdown = Utils.getComponentUnderTest(PATH_DROPDOWN2, DropDown.class, context);
Expand Down
23 changes: 23 additions & 0 deletions bundles/af-core/src/test/resources/form/dropdown/test-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,29 @@
"minItems" : 1,
"maxItems" : 2
},
"multiselect-dropdown-2" : {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType" : "core/fd/components/form/dropdown/v1/dropdown",
"name" : "abc",
"jcr:title" : "def",
"hideTitle" : true,
"description" : "dummy",
"visible" : false,
"assistPriority" : "custom",
"fieldType": "drop-down",
"dataRef" : "a.b",
"custom" : "Custom screen reader text",
"typeMessage" : "incorrect type",
"tooltip": "test-short-description",
"type" : "number[]",
"multiSelect" : true,
"fd:multiDefaultValues" : [0, 1],
"enum" : [0, 1, 2],
"enumNames" : ["m", "f", "o"],
"minItems" : 1,
"maxItems" : 2,
"required": true
},
"dropdown-datalayer": {
"id": "dropdown-bb1c9e883e",
"sling:resourceType": "core/fd/components/form/dropdown/v1/dropdown",
Expand Down