Rules based field in Content Fragment Model | Community
Skip to main content
October 9, 2025
Question

Rules based field in Content Fragment Model

  • October 9, 2025
  • 1 reply
  • 254 views

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

Karishma_begumSh
October 10, 2025

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.