I'm creating my settings page for a Wordpress plug-in, here is one of the fields to make a quick example:
add_settings_field(
'stwc_ft_oosn_0',
'Enable',
array( $this, 'stwc_ft_oosn_0_callback' ),
'settings-admin',
'stwc_ft_oosn_section'
);
Now in this case the field is a checkbox, how do I disable this conditionally? For example how do I disable it (not uncheck) depending on the value of another setting? Maybe using javascript? Is it safe?
I did this test but it is not working, I'm not sure if I'm moving in the right direction:
<script type="text/javascript">
jQuery(document).ready(function(){
document.addEventListener('click', UpdateFields(), false);
function UpdateFields(){
if ( !document.getElementById('stwc_ft_oosn_0').checked ) {
document.getElementById('stwc_ft_oosn_notice_1').setAttribute("disabled","disabled");
} else {
document.getElementById('stwc_ft_oosn_notice_1').removeAttribute("disabled");
}
//add other checks here
}
});
</script>