Page 1 of 1
Pop-up activated by column controlled by checkbox
Posted: 2020-08-26 07:53
by A Bindi
I have a column named "inactive" (integer) managed with a checkbox and I want to generate a popup that appears when a checkbox is clicked only when the control is checked, below the code in an_users-dv.js
Code: Select all
$j('#inactive').on('change', function(){
var inactive_v = $j('#inactive').val();
if (inactive_v == 1 ){
alert('Attention ! Before check this control verify that the user is not connected.');
}
});
The problem is that the alert appears when the control is checked and also when it is unchecked: i verified that the value returned by "inactive_v" variable is allways 1 and I does not figure out.
ALex
Re: Pop-up activated by column controlled by checkbox
Posted: 2020-08-26 09:53
by jsetzer
tl;dr
Code: Select all
var inactive_v = $j('#inactive').prop('checked');
---
Hi,
the value of a checkbox is
always 1 in AppGini generated integer/checkbox-fields (unless you change it).
Have a look at the sourcecode of your checkbox:

- chrome_fZ5Ml63XbZ.png (5.16 KiB) Viewed 2148 times
Solution
Instead of evaluating the value, you have to evaluate the
checked property of the field like this:
Code: Select all
var FIELDNAME_is_checked = $j("#FIELDNAME").prop("checked");
You can also change the checked-state by...
... passing
true ...
Code: Select all
$j("#FIELDNAME").prop("checked", true);
...or by passing
false ...
Code: Select all
$j("#FIELDNAME").prop("checked", false);
Console for illustration:

- chrome_Y5DVMInnXJ.png (8.7 KiB) Viewed 2148 times
Explanation of the console lines above
- get the value of an attribute named "value" of the field with id="is_hidden"
The .val() function looks like an alias for .attr("value") function
- returns "1" which equals the value of "value"-attribute of the <input> tag
- get the value of a property named "checked"
- returns false (=unchecked)
- check the field by settings the "checked" property value to true
- returns the field itself
- again, now after the change, get the value of a property named "checked"
- returns true (=checked)
Re: Pop-up activated by column controlled by checkbox
Posted: 2020-08-26 13:22
by A Bindi
Thank you a LOT Jsetzer for the exhaustive explanation !
I will apply the suggestions and will check the results.
ALex.
Re: Pop-up activated by column controlled by checkbox
Posted: 2020-08-27 13:55
by A Bindi
Thank you, it runs great !
ALex.
Re: Pop-up activated by column controlled by checkbox
Posted: 2020-08-27 15:59
by jsetzer
Hi Alex,
you are welcome. I'm happy that it works well!