Disable the save button depending on a field value

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Disable the save button depending on a field value

Post by SkayyHH » 2021-08-21 04:06

Hi,

does anyone of you have an idea to disable the save button depending on a field value?

Thanks very much, Kai

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

Re: Disable the save button depending on a field value

Post by pbottcher » 2021-08-23 16:11

Hi,

can you be a bit more specific on what type of field/situation you want to disable the save button?
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.

SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Disable the save button depending on a field value

Post by SkayyHH » 2021-08-24 04:11

Thank you very much for your help. I need information that is a prerequisite for creating a data record. It's about German data protection.

E.g. a checkbox or a text field with yes / no. If the check box is not set or the field is set to "no" and initially the save button should be disabled. if the checkbox is set or the field is set to yes, it should be enabled and can then be saved.

A bit like a "data protection consent" checkbox on a email form.

I hope I described it correctly.

Thank you very much!

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

Re: Disable the save button depending on a field value

Post by pbottcher » 2021-08-24 16:40

Hi,

for a checkbox you can try

Code: Select all

$j('#FIELDNAME').on('change',function(e) {if ($j(this).is(':checked')) {$j('#update').attr('disabled',false) } else {$j('#update').attr('disabled','disabled')}})
replace FIELDNAME with your fieldname for the checkbox. Also you should check at the beginning if the checkbox is already set and disable/enable the update botton accordingly.

If you are in the "insert" process for a record, use #insert instead of #update.
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.

SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Disable the save button depending on a field value

Post by SkayyHH » 2021-08-24 19:33

Hi,

thank you very much :-)

I try it next days.

Many greetings

SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Disable the save button depending on a field value

Post by SkayyHH » 2021-08-27 17:25

Hi,

i tried your code. Thank you very much again. Unfortunately I can't get it work. Is it correct that i put the code in the
tablename-dv.js in the hooks directory?

Thanks very much, Kai

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

Re: Disable the save button depending on a field value

Post by pbottcher » 2021-08-27 17:39

Hi Kai,

yes it is correct. But without more information (or even better a sample) it is hard to help more.
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.

SkayyHH
Veteran Member
Posts: 425
Joined: 2015-04-27 21:18

Re: Disable the save button depending on a field value

Post by SkayyHH » 2021-08-29 17:18

Hi,

sorry. You know, i´m not a coder ;-)

I tried

Code: Select all

$j('#consent').on('change',function(e) {if ($j(this).is(':checked')) {$j('#update').attr('disabled',false) } else {$j('#update').attr('disabled','disabled')}})
in

Code: Select all

/hooks/employees_de-dv.js
(this is my employee table).

"consent" is the field name of my checkbox.

The checkbox is intended to confirm that the employee agrees to their data being saved. If the checkbox is not set, I want to prevent the data set from being saved. I would like to disable the save button if the checkbox is not set and enable it if it is set.

Thank you very much, Kai

Alisson
Veteran Member
Posts: 81
Joined: 2017-02-25 20:32

Re: Disable the save button depending on a field value

Post by Alisson » 2021-09-07 00:33

I'm using this code to hide the button if group is not equal to Admins, place it in the /hooks/tablename.php
Inside the: function tablename_dv($selectedID, $memberInfo, &$html, &$args){

Code: Select all

if ($memberInfo["group"] != "Admins") {
    $html .= '<script>$j('#update').parents('.btn-group-vertical').hide();</script>';
}

User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Re: Disable the save button depending on a field value

Post by zibrahim » 2021-09-09 02:55

Thanks Alisson for the code.
Since the release of latest AG with the additional 'lock' icon on the right side of the "Save Changes" button, you may need to change the hide code to

Code: Select all

$j('#update').parents('.btn-group-lg').hide();
instead of

Code: Select all

$j('#update').parents('.btn-group-vertical').hide();
hope this will help someone.

Stay safe
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

Post Reply