Hide/Show Fields on Add Record

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
aduff
Posts: 23
Joined: 2020-10-24 15:01

Hide/Show Fields on Add Record

Post by aduff » 2020-11-01 14:16

Hi.
How can I show a hidden field (hidden in detail view (add record)) called 'text' when check box "show_text" has been clicked.

i.e. When adding a record in table_b I want the 'text' field hidden and only shown when "show_text" had been checked.
I also want the text field shown in detail view and table view if checked.

I have checked the forums with similar questions suggesting to add Java code to the 'tablename'-dv.js file in the hooks folder.

I've tried the below code with various alterations but to no avail... please note I don't know how to use Java.

/* hide unhide fields */
$j(function() {
if ($j("input#show_text").click(":checked")) {
$j("label[for='text']").show();}
})

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

Re: Hide/Show Fields on Add Record

Post by pbottcher » 2020-11-01 19:46

Hi,

how do you hide the field in detail view?

For your function, use

Code: Select all

$j("#show_text").on('change', function () {  
// if you want to show only the label
if ($(this).is(':checked')) {
  $j("label[for='text']").show();
}
else {
  $j("label[for='text']").hide();
}
})
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.

aduff
Posts: 23
Joined: 2020-10-24 15:01

Re: Hide/Show Fields on Add Record

Post by aduff » 2020-11-01 22:35

Hi pbottcher.

Thank you for a quick reply.

I have tried this in the <tablename>-dv.js file but does not show the field when 'show_text' is checked.

When I add a record and then check 'show_text' I want to see the 'text' field otherwise hide.

I only want to see the 'text' field in detail view and table view if 'show_text' is checked.

Thank you in advance.
Attachments
save_text.PNG
Screen shot of add record for table_b
save_text.PNG (11.14 KiB) Viewed 4625 times

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

Re: Hide/Show Fields on Add Record

Post by pbottcher » 2020-11-02 08:01

Hi,
you did not answer the question.

how do you hide the field in detail view?
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.

aduff
Posts: 23
Joined: 2020-10-24 15:01

Re: Hide/Show Fields on Add Record

Post by aduff » 2020-11-02 14:34

Hi.

Sorry, I did not answer...

I have initially hidden the field in Appgini so that it does not show on add record.
Attachments
save_text.hide.PNG
save_text.hide.PNG (15.53 KiB) Viewed 4605 times

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

Re: Hide/Show Fields on Add Record

Post by pbottcher » 2020-11-02 14:47

Hi,

if you use this feature, it is not possible to show the field, as the generated code will not have this field in the DV anymore.

So if you want to implement such a feature, you need to uncheck this feature and hide the field via JS through the hooks files, depending on your workflow.
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.

aduff
Posts: 23
Joined: 2020-10-24 15:01

Re: Hide/Show Fields on Add Record

Post by aduff » 2020-11-02 15:55

Hi.

I have unticked the [ ]Hide in details view but the text box is still showing when I click add record.

So if I tick whilst in add record screen it should show and untick it should be hidden, can this be done with the code in the dv.js file?

Code: Select all

$j("#show_text").on('change', function () {  
// if you want to show only the label
if ($(this).is(':checked')) {
  $j("label[for='text']").show();
}
else {
  $j("label[for='text']").hide();
}
})
Attachments
save_text.hidden.PNG
save_text.hidden.PNG (9.23 KiB) Viewed 4599 times

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

Re: Hide/Show Fields on Add Record

Post by pbottcher » 2020-11-02 16:45

Hi,

add a

$j("#show_text").parents('.form-group').hide();

at the beginning, before the

$j("#show_text").on('change', function () {
....

Also I would expect that

$j("label[for='text']").show(); $j("label[for='text']").hide();

will only hide the label, but not the text.

try rather:

$j("label[for='text']").parent('.form-group').show(); $j("label[for='text']").parent('.form-group').hide();
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.

aduff
Posts: 23
Joined: 2020-10-24 15:01

Re: Hide/Show Fields on Add Record

Post by aduff » 2020-11-02 17:41

Hi,

I have amended the code and now it is working!

However, after saving the record and then clicking on the record again the text field is hidden so to see the text I have to uncheck and then check the 'Show_text' field.

Code: Select all

$j("#text").parents('.form-group').hide();
$j("#show_text").on('change', function () {  
// if you want to show only the label
if ($j(this).is(':checked')) { 
	$j("label[for='text']").parent('.form-group').show();
}
else {
	$j("label[for='text']").parent('.form-group').hide();
}
});  
Attachments
after add record.PNG
After Record Added and in Detail View
after add record.PNG (9.6 KiB) Viewed 4588 times
add record.PNG
Add Record
add record.PNG (8.81 KiB) Viewed 4588 times

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

Re: Hide/Show Fields on Add Record

Post by pbottcher » 2020-11-02 19:54

Hi,

this is obvious, as you need to check of course the actual status of the field when the DV is opend.

So try

Code: Select all

if (!$j("#text").is('checked')) {
 $j("#text").parents('.form-group').hide();
}
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.

aduff
Posts: 23
Joined: 2020-10-24 15:01

Re: Hide/Show Fields on Add Record

Post by aduff » 2020-11-02 22:25

Hi.

I added the code to the beginning of the DV file but the '#text' field is still not visible when '#show_text' is checked.

I thought the 1st line should be '#show_text' so I tried this too but this did not work either.

Code: Select all

if (!$j("#text").is('checked')) {
	$j("#text").parents('.form-group').hide();
}
	 
$j("#show_text").on('change', function () {  
// if you want to show only the label
if ($j(this).is(':checked')) { 
	$j("label[for='text']").parent('.form-group').show();
}
else {
	$j("label[for='text']").parent('.form-group').hide();
}
});  
Attachments
Capture.PNG
Capture.PNG (2.47 KiB) Viewed 4565 times

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

Re: Hide/Show Fields on Add Record

Post by pbottcher » 2020-11-03 11:40

Hi,

true, of course it needs to be show_text. Aslo I missed to put the :, so please change it to

Code: Select all

if (!$j("#show_text").is(':checked')) {
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.

aduff
Posts: 23
Joined: 2020-10-24 15:01

Re: Hide/Show Fields on Add Record

Post by aduff » 2020-11-03 13:54

Excellent.

All works as expected, thank you so much for your time.

Post Reply