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: 1021
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: Learn all the tips and tricks of customizing AppGini apps through our online course.

:arrow: Mass Update plugin: Update multiple records at once and improve your workflow efficiency.

:arrow: Summary Reports plugin: Build powerful reports and charts for your AppGini apps.

:arrow: Search Page Maker: Compose user-friendly yet powerful search pages for your AppGini apps.

fgazza
Veteran Member
Posts: 70
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

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 525
Joined: 2018-04-01 10:12

Re: Conditional Hide/Unhide fields in detail view?

Post by pböttcher » 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.

Post Reply