Hide/show fields in Detail View

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
Jay Webb
Veteran Member
Posts: 55
Joined: 2017-08-26 15:27
Contact:

Hide/show fields in Detail View

Post by Jay Webb » 2019-07-30 05:32

Using AppGini: 5.76

Hello All,
I've tried a dozen different ways and no success, searched forums and nothing worked.
Setup:
In table Marriages, I have a field Other_Marriages that has 4 radio buttons, "None", "2nd Marriage", "3rd Marriage" and "4th Marriage".
In same table Marriages, I have 3 fields, Marriage_2, Marriage_3 and Marriage_4. (These are lookup fields.)

Goal:
In the "Marriages Detail View" when radio button "None" which is selected by default the fields Marriage_2, Marriage_3 and Marriage_4 are hidden.
When radio button Marriage_2 is selected, field Marriages_2 is shown.
When radio button Marriage_3 is selected, field Marriages_2 and Marriage_3 is shown.
And when radio button Marriage_4 is selected, field Marriages_2 and Marriage_3 and Marriage_4 are shown.

I'm was trying to make this as a hook, so as not to get overwritten on changes are published.
I realize I know just enough scripting to know very little, and after days of trying I'm here asking for assistance.

Any help is appreciated.
What we envision, we make happen.

User avatar
Jay Webb
Veteran Member
Posts: 55
Joined: 2017-08-26 15:27
Contact:

Re: Hide/show fields in Detail View

Post by Jay Webb » 2019-07-30 05:52

Here is what I tried in Marriages-dv.js

jQuery(function(){
jQuery('#Other_Marriages').click(function(){
if(jQuery(this).prop('Other_Marriages0')){ // Other_Marriages0, is "id" for None.
/* hide some stuff */
jQuery('#Marriage_2, #Marriage_3, #Marriage_4').hide();
}else{
/* show some stuff */
jQuery('#Marriage_2, #Marriage_3, #Marriage_4').show();
}
});
});

I get on errors, but also no change.
What we envision, we make happen.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 264
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Hide/show fields in Detail View

Post by jsetzer » 2019-07-30 08:24

I would recommend normalizing your tables:
Wouldn't it be better to have an additional table "marriages". Having this you are free to add as many marriages per person* as you need . For each marriage you will be able to enter date of marriage and end-date and perhaps more information, for example children born within that marriage, place of marriage, perhaps scans of marriage certificates etc..

Please don't get me wrong, it's just an idea which came into my mind when I read your question.

Regards,
Jan

* Remember Henry VIII. Tudor who has been married 8 times.

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

Re: Hide/show fields in Detail View

Post by pböttcher » 2019-07-30 09:13

Hi,

you can try to put this in your Marriages.php Marriages_dv function :

Code: Select all

	if(isset($_REQUEST['dvprint_x'])) return;		
	ob_start(); ?>
	<script>
	
$j(function(){
/* hide some stuff according to the already checked entry*/

if ($j("input#other_marriages2").is(":checked")) {
	$j("label[for='Marriage_2']").parent().hide();
	$j("label[for='Marriage_3']").parent().hide();	
}
else if ($j("input#other_marriages3").is(":checked")) {
	$j("label[for='Marriage_4']").parent().hide();	
}
else if ($j("input#other_marriages4").is(":checked")) {
}
else {
	$j("label[for='Marriage_2']").parent().hide();
	$j("label[for='Marriage_3']").parent().hide();
	$j("label[for='Marriage_4']").parent().hide();		
}
	$j("input[type=radio][name=marriages]").click(function(){
		switch($j(this).val()) {
			case 'none':
		$j("label[for='Marriage_2']").parent().hide();
		$j("label[for='Marriage_3']").parent().hide();
		$j("label[for='Marriage_4']").parent().hide();
		break;
			case '1':
		$j("label[for='Marriage_2']").parent().show();
		$j("label[for='Marriage_3']").parent().hide();
		$j("label[for='Marriage_4']").parent().hide();
		break;
			case '2':
		$j("label[for='Marriage_2']").parent().show();
		$j("label[for='Marriage_3']").parent().show();
		$j("label[for='Marriage_4']").parent().hide();
		break;
			case '3':
		$j("label[for='Marriage_2']").parent().show();
		$j("label[for='Marriage_3']").parent().show();
		$j("label[for='Marriage_4']").parent().show();
		break;
		default:
		}
	});
});	
	</script>
		
<?php
		
	$new_layout = ob_get_contents();
	ob_end_clean();
		
	$html .= $new_layout;
You need of course to verify that you put the correct names for other_marriages and Marriage_x according to the DOM of your page.

User avatar
Jay Webb
Veteran Member
Posts: 55
Joined: 2017-08-26 15:27
Contact:

Re: Hide/show fields in Detail View

Post by Jay Webb » 2019-07-30 09:15

Hi Jan

Yes, I have that as a look to table (Other Marriages) for all 4 lookup fields and all linked by FF Numbers (Family File Number) and having a lot of data entry fields I'd like to hide those to shorted the entry fields and show only if selected. I got to keep it simple as there will be 8 other people from 8 regions imputing data, Marriages, Baptisms/Births, Deaths, Surname spellings, Spouse Maiden, Age, Documentation, FF Numbers and FF Codes. Trying to keep it simple.
Any who, looking to hide and show depending on radio button selection, any ideas?
What we envision, we make happen.

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

Re: Hide/show fields in Detail View

Post by pböttcher » 2019-07-30 09:28

Just to add to my post, in the case statements you need of course to put your data instead of none, 1,2,3 reflecting your checkbox criteria.

onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 325
Joined: 2019-05-21 22:42
Contact:

Re: Hide/show fields in Detail View

Post by onoehring » 2019-07-30 09:30

Hi Jay,

you should consider normalizing your tables as Jan suggested. In my experience you are making yourself a lot more work, when you continue your path to the dark side of database design ;-)

Olaf

User avatar
Jay Webb
Veteran Member
Posts: 55
Joined: 2017-08-26 15:27
Contact:

Re: Hide/show fields in Detail View

Post by Jay Webb » 2019-07-30 17:07

Hi pböttcher

Wow, thanks for that code, I would have never figured that out as the method, I had to add the correct id's for none, 1,2,3, and, the fields hide, the only issue is the;

Code: Select all

$j("input[type=radio][name=marriages]").click(function(){
		switch($j(this).val())
selecting one of the radios has no effect until I Save Changes, then if I go back the field is exposed and everything works. I tried various id's in name=, I also checked with Inspect Element and no errors and the event show exactly as in the, "function Marriages_dv".

Results: fields are hidden and are exposed after Save Changes and return back to same Detail View.

Question: dose, dvprint_x also apply to, Add New page, I'm having same effect in that page as well. Or, do I need to have a second function for addNew_x.

I want you to know I'm very thankful for all your help, you always have a solution to odd requests.

Jay
What we envision, we make happen.

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

Re: Hide/show fields in Detail View

Post by pböttcher » 2019-07-30 18:41

Hi,

glad to see that it works half :-).

Sorry i forgot to mention that you need to change the marriage to name of your radio buttons. I guess it is Other_Marriages, but not sure.
You can check it through the development console and have a look at your radio buttons.

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

Re: Hide/show fields in Detail View

Post by pböttcher » 2019-07-30 19:38

Additional to your question.

The

if(isset($_REQUEST['dvprint_x'])) return;

is just used if you try to print the page, as the logic does not necessarily apply. If it does for you, you can leave it out.

User avatar
Jay Webb
Veteran Member
Posts: 55
Joined: 2017-08-26 15:27
Contact:

Re: Hide/show fields in Detail View

Post by Jay Webb » 2019-07-30 20:02

Hi,

Just spent the last hour and half normalizing my tables and fields as was being suggested.
I made the change to name of radio button as shown in the console, even ran debugger and no change and debugger says it's all good.
Here's what I got;

Code: Select all

		function marriage_dv($selectedID, $memberInfo, &$html, &$args){

			if(isset($_REQUEST['dvprint_x'])) return;
	ob_start(); ?>

<script>
	
$j(function(){
/* hide some stuff according to the already checked entry*/

if ($j("input#other_marriages1").is(":checked")) {
	$j("label[for='marriage_2']").parent().hide();
	$j("label[for='marriage_3']").parent().hide();	
}
else if ($j("input#other_marriages2").is(":checked")) {
	$j("label[for='marriage_4']").parent().hide();	
}
else if ($j("input#other_marriages3").is(":checked")) {
}
else {
	$j("label[for='marriage_2']").parent().hide();
	$j("label[for='marriage_3']").parent().hide();
	$j("label[for='marriage_4']").parent().hide();		
}
	$j("input[type=radio][name=other_marriages]").click(function() {
		switch($j(this).val()) {
			case 'other_marriages0':                          /*none = 1st Marriage*/
		$j("label[for='marriage_2']").parent().hide();
		$j("label[for='marriage_3']").parent().hide();
		$j("label[for='marriage_4']").parent().hide();
		break;
			case 'other_marriages1':                         /*2nd Marriage*/
		$j("label[for='marriage_2']").parent().show();
		$j("label[for='marriage_3']").parent().hide();
		$j("label[for='marriage_4']").parent().hide();
		break;
			case 'other_marriages2':                         /*3rd Marriage*/
		$j("label[for='marriage_2']").parent().show();
		$j("label[for='marriage_3']").parent().show();
		$j("label[for='marriage_4']").parent().hide();
		break;
			case 'other_marriages3':                        /*4th Marriage*/
		$j("label[for='marriage_2']").parent().show();
		$j("label[for='marriage_3']").parent().show();
		$j("label[for='marriage_4']").parent().show();
		break;
		default:
		}
	});
});	
	</script>
		
<?php
		
	$new_layout = ob_get_contents();
	ob_end_clean();
		
	$html .= $new_layout;
	}
see any errors? do I need a return at the very end.
What we envision, we make happen.

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

Re: Hide/show fields in Detail View

Post by pböttcher » 2019-07-30 20:24

Hi,

can you post a screenshot of the debugger showing the other_marriages name pls.

User avatar
Jay Webb
Veteran Member
Posts: 55
Joined: 2017-08-26 15:27
Contact:

Re: Hide/show fields in Detail View

Post by Jay Webb » 2019-07-30 21:30

Ok, I think this will work.

Image
Image
What we envision, we make happen.

Ionut Bocanet
Posts: 24
Joined: 2017-03-12 09:26
Contact:

Re: Hide/show fields in Detail View

Post by Ionut Bocanet » 2019-10-18 08:10

Dear Sirs,

Helppp ! :(

I have 3 parent tables and 1 child table.

the child table is linked with all 3 parent tables.

Based on the new entry that i do , from one parent, or the other i want in the detail view of the child to hide some fields.

I tried multiple examples based on the topics found on this forum but i failed.

I attached the detail view of the child table, as you will see, are a lot of fields.

I attached also a scheme of what i would want to do.

Please advise who can help me.
Attachments
example of flow.png
example of flow.png (17.9 KiB) Viewed 322 times
detail view.png
detail view.png (213.25 KiB) Viewed 322 times
Best Regards,
Ionut Bocanet

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

Re: Hide/show fields in Detail View

Post by pböttcher » 2019-10-18 11:07

Hi,

I dont see a field "is Action Plan" on the image.

When shall the field1 be hidden? "is Action Plan" is not empty or it is "Action Plan" ? So if it not empty it shall be hidden? As this happens if there is an Action_Plan_ID, you could check for that already, correct?
What code did you try?

Ionut Bocanet
Posts: 24
Joined: 2017-03-12 09:26
Contact:

Re: Hide/show fields in Detail View

Post by Ionut Bocanet » 2019-10-18 17:56

I tried the code format as below

jQuery(function(){
jQuery('#T1').function(){
if(jQuery(this)=='ActionPlan')){
/* hide some stuff */
jQuery('#Category, #Duration, #Commitment, #CI_UID, #Meeting_UID').hide();
}else{
/* show some stuff */
jQuery('#Category, #Duration, #Commitment, #CI_UID, #Meeting_UID')
}
});
});

But i want at Detail View Load, based on the field T1 if it is "ActionPlan" to hide the fields as stated in the image.

The code above is modified based on a click field which was hiding some fields when was clicked, but and i need at the load to have already the fields hidden based on the existing value which is "Action Plan".
Attachments
example 2.png
example 2.png (45.58 KiB) Viewed 297 times
Best Regards,
Ionut Bocanet

Post Reply