First, give your container a class, for example: toggle-container. This will mark the containers where clicking anywhere inside should toggle the checkbox.
Then create a JavaScript action (for example EnableToggleContainer) and add this code:
export function EnableToggleContainer() {
document.addEventListener("click", function (e) {
var container = e.target.closest(".toggle-container");
if (!container) return;
// If the user clicked directly on the checkbox, do nothing
if (e.target.type === "checkbox") return;
var checkbox = container.querySelector("input[type='checkbox']");
if (checkbox && !checkbox.disabled) {
checkbox.click();
}
});
}
Call this JavaScript action once when the page loads (for example in the page’s On load microflow). After that, any container with the class toggle-container will toggle its child checkbox when clicked.
If this resolves the issue, please close the topic.
Hi Didier Dujardin
Not natively; a container click won’t toggle a child Checkbox out‑of‑the‑box. With only platform‑supported options, the clean pattern is: wrap the Checkbox in a Container and set the Container’s On click → Nanoflow that toggles the underlying Boolean (Change object: MyAttr = not($current/MyAttr); optionally commit/refresh). Make it generic/reusable by putting this in a Snippet/Building block that takes the context object; you reuse the same nanoflow everywhere without touching DOM. If you really want a true “click anywhere inside container to flip the checkbox” behavior, you can still stay platform‑supported by using a JavaScript action (called from the container’s On click nanoflow) that finds and toggles the first checkbox within the clicked container. just note DOM selectors can be brittle, so the Boolean‑toggle nanoflow approach is the Mendix‑best‑practice.
I hope this helps!!
Hi,
Yes, this is possible in Mendix using only platform-supported functionality.
However, it cannot be done purely with CSS. It must be handled either through a microflow/nanoflow or through standard HTML label behavior.
Below are the correct approaches.
Since you are allowed to use platform-supported widgets, the proper way is:
not $currentObject/YourBooleanAttribute
This toggles the checkbox value cleanly and works everywhere.
This approach is:
If the checkbox is bound to a Boolean attribute and is inside the same data view:
Wrap the checkbox inside a Label widget.
HTML behavior automatically toggles a checkbox when its associated label is clicked.
Steps:
This is native HTML behavior and fully supported.
However, this works best when layout allows proper label association.
If you need this pattern in many places:
Create a small reusable building block:
Container
This keeps behavior consistent and maintainable.
Yes, it is possible.
The correct and supported solution is to toggle the Boolean attribute using a container click event and a nanoflow.
CSS alone cannot change the checkbox value.
JavaScript DOM manipulation is not recommended.
Using a container click nanoflow is the cleanest Mendix-native solution.
Hi Ahmet,
I've got it working ;-)
Thanks
Still a question:
If I would use this in multiple pages do I need to call this JS in every page where I want to use this or can I call this once in the session (lets say at login or so) and use it on different pages.
I'm also still wondering if I can make it work with a Building Block because that would make it still easier but no idea if that can work ... will try that latter