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
Conditional Hide/Unhide fields in detail view?
Re: Conditional Hide/Unhide fields in detail view?
Sorry to bother, did you solve this?
Thanks
iR
Thanks
iR
Re: Conditional Hide/Unhide fields in detail view?
Nope. I did not manage to solve this one.
Re: Conditional Hide/Unhide fields in detail view?
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:
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.
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();
}
});
});
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.
Re: Conditional Hide/Unhide fields in detail view?
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
Thank you!
Fabiano
Re: Conditional Hide/Unhide fields in detail view?
Hi,
you can add to you hooks/TABLENAME.php tablename_dv function.
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.
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;
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.
Re: Conditional Hide/Unhide fields in detail view?
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 !
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 !