Pop-up activated by column controlled by checkbox

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
A Bindi
Veteran Member
Posts: 51
Joined: 2018-01-04 18:45

Pop-up activated by column controlled by checkbox

Post by A Bindi » 2020-08-26 07:53

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

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1814
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Pop-up activated by column controlled by checkbox

Post by jsetzer » 2020-08-26 09:53

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
chrome_fZ5Ml63XbZ.png (5.16 KiB) Viewed 1500 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
chrome_Y5DVMInnXJ.png (8.7 KiB) Viewed 1500 times

Explanation of the console lines above
  1. 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
  2. returns "1" which equals the value of "value"-attribute of the <input> tag
  3. get the value of a property named "checked"
  4. returns false (=unchecked)
  5. check the field by settings the "checked" property value to true
  6. returns the field itself
  7. again, now after the change, get the value of a property named "checked"
  8. returns true (=checked)
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

A Bindi
Veteran Member
Posts: 51
Joined: 2018-01-04 18:45

Re: Pop-up activated by column controlled by checkbox

Post by A Bindi » 2020-08-26 13:22

Thank you a LOT Jsetzer for the exhaustive explanation !
I will apply the suggestions and will check the results.

ALex.

A Bindi
Veteran Member
Posts: 51
Joined: 2018-01-04 18:45

Re: Pop-up activated by column controlled by checkbox

Post by A Bindi » 2020-08-27 13:55

Thank you, it runs great !

ALex.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1814
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Pop-up activated by column controlled by checkbox

Post by jsetzer » 2020-08-27 15:59

Hi Alex,
you are welcome. I'm happy that it works well!
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply