Disable SAVE NEW button on render

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Disable SAVE NEW button on render

Post by pfrumkin » 2022-03-12 17:17

Hi,

I have a use case very much like viewtopic.php?t=4446. I do not want to allow a new record to be saved unless an agreement box is checked. The advice from @pböttcher is perfect for the checkbox change event

Code: Select all

	$j('#Confidentiality_Agree').on('change',function(e) {
		if ($j(this).is(':checked')) {
			$j('#insert').attr('disabled',false) 
		} else {
			$j('#insert').attr('disabled','disabled')
		}
	});
My problem is on initial render. I have added the line

Code: Select all

$j('#insert').attr('disabled','disabled');
and I can see it work when I step through the code, but then something comes along and enables the button after my code runs. I am sure that this is some order of operation thing, and the (tablename_dv) hook or .js file runs before running something else that turns the button on.

Anyone have any ideas for how to disable the SAVE NEW button on the initial render?

Thanks.

~Paul
AG 5.84

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

Re: Disable SAVE NEW button on render

Post by pbottcher » 2022-03-13 13:39

Hi,

try to add to the footer in hooks/TABLENAME.php

Code: Select all

			
	case 'detailview':
		$footer='<%%FOOTER%%><script>debugger;$j("#insert").attr("disabled","disabled");</script>';
		break;
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.

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Disable SAVE NEW button on render

Post by pfrumkin » 2022-03-14 16:08

Thanks, but still no luck. After breaking and stepping at this line, I can see that the disabled attribute is set to true, but when I click run, the button is available, and I can see the attribute set to false.

~Paul

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

Re: Disable SAVE NEW button on render

Post by pbottcher » 2022-03-14 16:27

What version of AppGini?
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.

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Disable SAVE NEW button on render

Post by pfrumkin » 2022-03-14 16:44

AG 5.84

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

Re: Disable SAVE NEW button on render

Post by pbottcher » 2022-03-14 20:01

Hi,

do you have any other scripts running?
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.

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Disable SAVE NEW button on render

Post by pfrumkin » 2022-03-14 20:14

Not that I know of. I rebooted this morning and get the same result.

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Disable SAVE NEW button on render

Post by pfrumkin » 2022-03-14 20:26

My dev environment is Windows 10 and I am running localhost. Our production site is Linux. I have seen subtle differences in the past between the two, so that could always be a thing. In the absence of any other answers, I will work to pushing to production and see if it repros there.

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

Re: Disable SAVE NEW button on render

Post by pbottcher » 2022-03-15 21:25

Can you just create a simple app with one table and add only that code to see if the same happens.
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.

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Disable SAVE NEW button on render

Post by pfrumkin » 2022-03-16 14:13

Sure I will try that, not sure how quickly I can do that.

I did push this live and it does repro on our Linux host. This is not a showstopper as this is a new requirement anyway, consumers have been able to save records now without checking the box so this isn't really a new behavior.

You think it would matter that I am using the tablename_dv hook as well as the JS file?

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

Re: Disable SAVE NEW button on render

Post by pbottcher » 2022-03-16 19:19

Hi again,

that should not cause any issues. But what JS are you using there?
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.

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Disable SAVE NEW button on render

Post by pfrumkin » 2022-03-17 15:34

A tablename-dv.js script

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Disable SAVE NEW button on render

Post by pfrumkin » 2022-03-23 01:43

A bit of a hack, but I solved by hiding the button until the checkbox is updated. If checked, the button is enabled, if unchecked the button is disabled.

I'm not a JS guy so I'm not sure about this flow, but it looks like after we go into the tablename-dv.js script, we go into the lightbox.min.js, so I suspect something in there enables the button. I don't know how or if the button can be controlled as I was trying.

Paul

Post Reply