Conditional Hide/Unhide fields in detail view?

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
KSan
AppGini Super Hero
AppGini Super Hero
Posts: 252
Joined: 2013-01-08 20:17

Conditional Hide/Unhide fields in detail view?

Post by KSan » 2014-01-03 06:44

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

I.Roberto
Posts: 5
Joined: 2013-06-28 00:52

Re: Conditional Hide/Unhide fields in detail view?

Post by I.Roberto » 2014-10-22 21:53

Sorry to bother, did you solve this?
Thanks
iR

KSan
AppGini Super Hero
AppGini Super Hero
Posts: 252
Joined: 2013-01-08 20:17

Re: Conditional Hide/Unhide fields in detail view?

Post by KSan » 2014-11-04 06:02

Nope. I did not manage to solve this one.

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Conditional Hide/Unhide fields in detail view?

Post by a.gneady » 2014-11-04 21:04

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.
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Re: Conditional Hide/Unhide fields in detail view?

Post by fgazza » 2019-07-30 15:58

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

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Conditional Hide/Unhide fields in detail view?

Post by pbottcher » 2019-07-30 19:56

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.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Conditional Hide/Unhide fields in detail view?

Post by pfrumkin » 2020-05-05 21:01

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 !

Post Reply