Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Rules based field in Content Fragment Model

Avatar

Level 1

Hi, how can I create a rules based field in content fragment model. For example, there is a enum field called fuel type; if the fuel type is electric, then a new field, battery power, should pop up or should be populated. If the fuel type is any other, the battery power field couldn’t be populated or shown. How can I do this? Thank you.

1 Reply

Avatar

Level 5

Hi @SixMu 

AEM Content Fragment Models don’t support native conditional fields.

Create both fields (fuelType, batteryPower).

Add help text to batteryPower:

“Only fill if fuel type = Electric.”

Add a clientlib for the fragment editor and use JS to show/hide the field:

(function ($, document) {
  $(document).on("foundation-contentloaded", function () {
    const fuel = $("coral-select[name='./fuelType']");
    const battery = $("input[name='./batteryPower']").closest(".coral-Form-fieldwrapper");
    function toggle() { fuel.val() === "Electric" ? battery.show() : battery.hide(); }
    fuel.on("change", toggle);
    toggle();
  });
})(Granite.$, document);

 

Hope this helpful:)

 

Regards,

Karishma.