Page 1 of 1

Conditional Hide/Unhide fields in detail view?

Posted: 2014-01-03 06:44
by KSan
Hi,

I have a table where a checkbox is to control whether certain fields are to be shown or not. In other words if this checkbox is not checked then a number of fields are not relevant and should not be shown. I can set my table to hide these fields initially. How can I make them visible inside a hook conditional upon the state of the checkbox?

Thanks much for your help

Re: Conditional Hide/Unhide fields in detail view?

Posted: 2014-10-22 21:53
by I.Roberto
Sorry to bother, did you solve this?
Thanks
iR

Re: Conditional Hide/Unhide fields in detail view?

Posted: 2014-11-04 06:02
by KSan
Nope. I did not manage to solve this one.

Re: Conditional Hide/Unhide fields in detail view?

Posted: 2014-11-04 21:04
by a.gneady
In the hooks folder, edit the file "tablename-dv.js" (or create it if it's not there -- where tablename is the name of the concerned table) ... you should put in something like this:

Code: Select all

jQuery(function(){
    jQuery('#id-of-checkbox').click(function(){
         if(jQuery(this).prop('checked')){
             /* hide some stuff */
             jQuery('#id1, #id2, #id3').hide();
         }else{
             /* show some stuff */
             jQuery('#id1, #id2, #id3').show();
         }
    });
});
You can get element IDs to put into the above code by inspecting the page using Firebug plugin for Firefox or the inspector in Chrome.

Re: Conditional Hide/Unhide fields in detail view?

Posted: 2019-07-30 15:58
by fgazza
I also need a solution like this. The particularity of my goal concerns the fact that the hidden fields should become visible when in a list of options of a multi select check box containing options 1 2 3 4 5 option 5 is selected. How can I change the code in the tablename_dv-js file?

Thank you!

Fabiano

Re: Conditional Hide/Unhide fields in detail view?

Posted: 2019-07-30 19:56
by pbottcher
Hi,

you can add to you hooks/TABLENAME.php tablename_dv function.

Code: Select all

	if(isset($_REQUEST['dvprint_x'])) return;		
	ob_start(); ?>
	<script>
	
$j(function(){
	if ($j("#field2 option[value=texttocheckfor]:selected").length == 0){
    $j("label[for='field3']").parent().hide();
}
/* hide some stuff according to the already checked entry*/
$j('#field2').click(function(){
if ($j("#field2 option[value=texttocheckfor]:selected").length == 1){
    $j("label[for='field3']").parent().show();
}
else {
	$j("label[for='field3']").parent().hide();
}

});
});	
	</script>
		
<?php
		
	$new_layout = ob_get_contents();
	ob_end_clean();
		
	$html .= $new_layout;
	
replace field2 with the fieldname that contains the multiselect, field3 with the name of the field that you want to hide and the texttocheckfor with the value when you want the field to appear.

Re: Conditional Hide/Unhide fields in detail view?

Posted: 2020-05-05 21:01
by pfrumkin
Combine with viewtopic.php?t=465 and tweak a little (courtesy another post on git), use this to hide columns in detail view based on group membership

if(isset($_REQUEST['dvprint_x'])) return;
$memberInfo = getMemberInfo();
if($memberInfo['group'] !='Admins') {
ob_start();
?>
<script>
$j(function(){
$j('#Status').parents('.form-group').hide();
})
</script>

<?php
$new_layout = ob_get_contents();
ob_end_clean();

$html .= $new_layout;
}

Thanks @pböttcher !