I actually had to modify this a little bit and figured I would share what I did here in case anyone else stumbles into this post. There were three main areas that I had to account for:
- Frequently errors out because it attempts to load django.jQuery before it is ready.
- Hide was not working in general (not sure why)
- Wanted to do the inverse, hiding unless the option was checked.
So, this solves all three of those problems for me. We do the following:
- Delay calling the function
- Hide the .form-row.field-, to hide an entire row (I recommend using chromes inspect feature to find the name of the row you want to hide.)
- We do the inverse, hiding the section as soon as the page is done loading and then unhiding if the box is checked.
So this is my final code:
window.addEventListener("load", function() {
(function() {
show_page=false;
django.jQuery(document).ready(function(){
if (django.jQuery('#id_override_timeline').is(':checked')) {
django.jQuery(".form-row.field-next_milestone").show();
show_page=true;
} else {
django.jQuery(".form-row.field-next_milestone").hide();
show_page=false;
}
django.jQuery("#id_override_timeline").click(function(){
show_page=!show_page;
if (show_page) {
django.jQuery(".form-row.field-next_milestone").show();
} else {
django.jQuery(".form-row.field-next_milestone").hide();
}
})
})
})(django.jQuery);
});
I hope this helps someone else who stumbles on this post!