Page 1 of 1

Disable the save button depending on a field value

Posted: 2021-08-21 04:06
by SkayyHH
Hi,

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

Thanks very much, Kai

Re: Disable the save button depending on a field value

Posted: 2021-08-23 16:11
by pbottcher
Hi,

can you be a bit more specific on what type of field/situation you want to disable the save button?

Re: Disable the save button depending on a field value

Posted: 2021-08-24 04:11
by SkayyHH
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!

Re: Disable the save button depending on a field value

Posted: 2021-08-24 16:40
by pbottcher
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.

Re: Disable the save button depending on a field value

Posted: 2021-08-24 19:33
by SkayyHH
Hi,

thank you very much :-)

I try it next days.

Many greetings

Re: Disable the save button depending on a field value

Posted: 2021-08-27 17:25
by SkayyHH
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

Re: Disable the save button depending on a field value

Posted: 2021-08-27 17:39
by pbottcher
Hi Kai,

yes it is correct. But without more information (or even better a sample) it is hard to help more.

Re: Disable the save button depending on a field value

Posted: 2021-08-29 17:18
by SkayyHH
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

Re: Disable the save button depending on a field value

Posted: 2021-09-07 00:33
by Alisson
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>';
}

Re: Disable the save button depending on a field value

Posted: 2021-09-09 02:55
by zibrahim
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