How to use clientlib for content fragment?
Hi All,
I have created a content fragment that includes two data types: a checkbox and a number field. I want to add custom behavior so that the number field is only visible when the checkbox is checked. I have created a client library under /apps/clientlibs with the category dam.cfm.authoring.contenteditor.v2. Here is my JavaScript code:
Coral.commons.ready(document.querySelector('input[name="itemOrderable"]'), function(checkbox) {
var fieldToToggle = document.getElementById('coral-id-122').closest('.coral-Form-fieldwrapper');
function toggleField() {
console.log("Checkbox checked:", checkbox.checked);
if (checkbox.checked) {
fieldToToggle.style.display = 'block';
} else {
fieldToToggle.style.display = 'none';
}
}
toggleField();
checkbox.on("change", function() {
toggleField();
location.reload();
});
});
This code works, but I need to refresh the page to see the result whenever I check or uncheck the checkbox.
Thank you!