Skip to content

containerCssClass setting has no effect with Select2 4.1.0 - should map to selectionCssClass #1437

@matutet

Description

@matutet

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions