Page 1 of 1
Disable SAVE NEW button on render
Posted: 2022-03-12 17:17
by pfrumkin
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
Re: Disable SAVE NEW button on render
Posted: 2022-03-13 13:39
by pbottcher
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;
Re: Disable SAVE NEW button on render
Posted: 2022-03-14 16:08
by pfrumkin
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
Re: Disable SAVE NEW button on render
Posted: 2022-03-14 16:27
by pbottcher
What version of AppGini?
Re: Disable SAVE NEW button on render
Posted: 2022-03-14 16:44
by pfrumkin
AG 5.84
Re: Disable SAVE NEW button on render
Posted: 2022-03-14 20:01
by pbottcher
Hi,
do you have any other scripts running?
Re: Disable SAVE NEW button on render
Posted: 2022-03-14 20:14
by pfrumkin
Not that I know of. I rebooted this morning and get the same result.
Re: Disable SAVE NEW button on render
Posted: 2022-03-14 20:26
by pfrumkin
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.
Re: Disable SAVE NEW button on render
Posted: 2022-03-15 21:25
by pbottcher
Can you just create a simple app with one table and add only that code to see if the same happens.
Re: Disable SAVE NEW button on render
Posted: 2022-03-16 14:13
by pfrumkin
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?
Re: Disable SAVE NEW button on render
Posted: 2022-03-16 19:19
by pbottcher
Hi again,
that should not cause any issues. But what JS are you using there?
Re: Disable SAVE NEW button on render
Posted: 2022-03-17 15:34
by pfrumkin
A tablename-dv.js script
Re: Disable SAVE NEW button on render
Posted: 2022-03-23 01:43
by pfrumkin
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