Urgent Help Needed On JS Magic Hook

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
tandrew
Posts: 12
Joined: 2018-09-26 12:46

Urgent Help Needed On JS Magic Hook

Post by tandrew » 2018-10-08 13:02

Hi to all expert out there,

using appgini 5.72

created a magic table hook called dpt_ctasbly_req-tv.js

Inside have this function

Code: Select all

$j(function(){

$('#leave_panel_clinic').parents('.form-group').hide();

	$j('#leave_application_type').on('change', function(){
		if($j('#leave_application_type').val () == 'SL-SICK LEAVE'){
			$j('#leave_panel_clinic').parents('.form-group').show();
		}else{
			$j('#leave_panel_clinic').parents('.form-group').hide();
			$j('#leave_panel_clinic').focus().select();
		}
	})
})
On page load the leave_panel_field should be hidden until leave_application_type value = SL-SICK LEAVE which is working fine.

Problem is when submit/update, the leave_panel_clinic will not show in detail. Suspected first line $('#leave_panel_clinic').parents('.form-group').hide(); cause the issue.

If remove $('#leave_panel_clinic').parents('.form-group').hide(); it will not hide on page load which is not what i want. This leave_panel_clinic field should be hidden until leave_application_type selected value is SL-SICK LEAVE then will show.

leave_application_type is dropdown value to select from.
leave_panel_clinic is dropdown value to select from.

I was wondering which part went wrong.

Help~

Thanks in advance.

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

Re: Urgent Help Needed On JS Magic Hook

Post by pböttcher » 2018-10-08 14:12

Hi,

you are missing the j in your statement.

Code: Select all

$('#leave_panel_clinic').parents('.form-group').hide();
should be

Code: Select all

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

tandrew
Posts: 12
Joined: 2018-09-26 12:46

Re: Urgent Help Needed On JS Magic Hook

Post by tandrew » 2018-10-08 23:21

hi thanks for the reply,

Even at the $j in front still does not solve the issue i've face.

Already clear the cache and everything still facing the same issue

leave_panel_clinic will not show after submit. It goes into hiding.

If remove $j('#leave_panel_clinic').parents('.form-group').hide(); then it will show after submit but will not hide on load.

Was wondering is the newer chrome + firefox version causing the issue on Java side.

Thanks.

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

Re: Urgent Help Needed On JS Magic Hook

Post by pböttcher » 2018-10-09 06:35

Hi,

can you post some screenshots? On my testsystem it works just fine.

tandrew
Posts: 12
Joined: 2018-09-26 12:46

Re: Urgent Help Needed On JS Magic Hook

Post by tandrew » 2018-10-09 08:33

Hi,

Thanks so much for the response.

I'm not so sure why magic JS hook is not working so well.

Currently i'm using table_hook.dv to parse the JS which is working as i want it to be with few modifications here and there.
(although not as friendly as magic JS hook file)

Additionally, found out the group member must have edit rights so the JS will work. If the group cannot edit then it will not work. Strange

In that case i have to make all selectable field => read-only based on non-admin hidden condition

When i have time will show you the full pictures on what happen.

Using appgini 5.72 and not sure it's bug issue or my code issue.

Thanks for now.

Will keep posted as i'm rushing to finish the project.

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

Re: Urgent Help Needed On JS Magic Hook

Post by pböttcher » 2018-10-09 08:58

Hi,

I thought about what you wrote. You are hiding the leave_panel_clinic every time you call the js code. Hence after save / Submit you hide the field again.
You do not check wether the leave_application_type').val () == 'SL-SICK LEAVE' which you would need, not to hide the leave_panel_clinic.

You can try

if($j('#leave_application_type').val () != 'SL-SICK LEAVE'){
$('#leave_panel_clinic').parents('.form-group').hide();
}

tandrew
Posts: 12
Joined: 2018-09-26 12:46

Re: Urgent Help Needed On JS Magic Hook

Post by tandrew » 2018-10-10 03:57

Hi,

Thanks for the response.

Not that i want it to be this way. It's still show upon load and when you click on the leave_application_type other than SL-SICK LEAVE then it will hide.

Need it to be hide upon load and show after submit/update in Detail View.

Until now it is strange that Magic JS Hook file is not working as it is.

Hence have to use table.dv hook to parse the html as shown below code.

// Hide Leave Panel Clinic Until Leave Application Type == SL-SICK LEAVE

Code: Select all

		 $html .= <<<EOC
					<script>
						\$j(function(){
							\$j('#leave_panel_clinic').parents('.form-group').hide();
							\$j('#leave_application_type').on('change', function(){
								if(\$j('#leave_application_type').val () == "SL-SICK LEAVE"){
							\$j('#leave_panel_clinic').parents('.form-group').show();
								}else{
							\$j('#leave_panel_clinic').parents('.form-group').hide();
							\$j('#leave_panel_clinic').focus().select();
								}
							})
						})										
					</script>
EOC;

// Show Leave Panel Clinic In Detail View When Leave Application Type == SL-SICK LEAVE

Code: Select all

	if( ( $selectedID ) ){	
		 $html .= <<<EOC
					<script>
						\$j(function(){
						if(\$j('#leave_application_type').val () == "SL-SICK LEAVE"){
							\$j('#leave_panel_clinic').parents('.form-group').show();	
						}	
					})													
					</script>
EOC;
		}
For at least this method is working fine for me.

Anyway, thanks for the help.

Much appreciated.

Regards.

Post Reply