But it is not dynamic, you need to save record and again go to edit view.
Maybe I need to do it using vanilla JS code.
Suggested by AI:
custom/modules/Accounts/js/conditional_fields.js
// This script toggles the visibility of the text field based on the checkbox state
document.addEventListener('DOMContentLoaded', function() {
var checkboxField = document.querySelector('[name="checkbox_field"]');
var textField = document.querySelector('[name="text_field"]');
// Function to handle the toggle of the text field visibility
function toggleTextField() {
if (checkboxField.checked) {
textField.style.display = 'block'; // Show the text field
} else {
textField.style.display = 'none'; // Hide the text field
}
}
// Initialize the display state based on the checkbox status
toggleTextField();
// Add an event listener to the checkbox to update the text field visibility
checkboxField.addEventListener('change', toggleTextField);
});
create a javascript file at custom/modules/{Module}/js/jscript.js with the following code. Please replace your checkbox field id and field id to hide or show.
function hideshow(){
var ckbox = document.getElementById('internal');
if(ckbox.checked){
document.getElementById('addFileButton').style.display='none';
document.querySelector("div[data-label='LBL_CASE_UPDATE_FORM']").style.display='none';
} else {
document.getElementById('addFileButton').style.display='block';
document.querySelector("div[data-label='LBL_CASE_UPDATE_FORM']").style.display='block';
}
}
copy metadata file from modules/{Module}/metadata/editviewdefs.php at custom/modules/{Module}/metadata/editviewdefs.php and include the javascript file path as shown below in the ‘includes’ array
Then I did QR&R and hard reload and clear cache on the browser page.
I went to edit page of the module. The text field is still displaying. Then, I click on checkbox and I am getting the below error in the console. What am I doing wrong?
Uncaught ReferenceError: hideshow is not defined
at HTMLInputElement.onchange
Can you please add the following code after hideshow() function in the JScript.js as show below. The checkbox is set checked and called hideshow() method.