Problem
Settings.setContainerCssClass("my-class") has no effect on the rendered DOM. The class is not applied to any element.
Root cause
In Settings.toJson() (line 124), the setting is serialized as:
Json.writeObject(writer, "containerCssClass", containerCssClass);
But Select2 4.1.0 (bundled in wicketstuff-select2 9.22.0) removed containerCssClass. The equivalent option is selectionCssClass, which applies the class to the .select2-selection element.
Reference: https://select2.org/configuration/options-api
Verified behavior
dropdownCssClass → works correctly (applied to .select2-dropdown)
containerCssClass → ignored by Select2 4.1.0 JS (no element receives the class)
- Changing the JSON key from
"containerCssClass" to "selectionCssClass" in Settings.toJson() fixes the issue: the class is applied to .select2-selection
Suggested fix
In Settings.java, line 124, change:
Json.writeObject(writer, "containerCssClass", containerCssClass);
to:
Json.writeObject(writer, "selectionCssClass", containerCssClass);
The Java API (setContainerCssClass/getContainerCssClass) can remain unchanged for backwards compatibility, or be renamed to setSelectionCssClass with the old method deprecated.
Environment
- wicketstuff-select2: 9.22.0
- Select2 JS bundled: 4.1.0-rc.0
- Wicket: 9.22.0
Problem
Settings.setContainerCssClass("my-class")has no effect on the rendered DOM. The class is not applied to any element.Root cause
In
Settings.toJson()(line 124), the setting is serialized as:But Select2 4.1.0 (bundled in wicketstuff-select2 9.22.0) removed
containerCssClass. The equivalent option isselectionCssClass, which applies the class to the.select2-selectionelement.Reference: https://select2.org/configuration/options-api
Verified behavior
dropdownCssClass→ works correctly (applied to.select2-dropdown)containerCssClass→ ignored by Select2 4.1.0 JS (no element receives the class)"containerCssClass"to"selectionCssClass"inSettings.toJson()fixes the issue: the class is applied to.select2-selectionSuggested fix
In
Settings.java, line 124, change:to:
The Java API (
setContainerCssClass/getContainerCssClass) can remain unchanged for backwards compatibility, or be renamed tosetSelectionCssClasswith the old method deprecated.Environment