How to: Show/Hide custom message on checkbox-click

This sub-forum is for discussing all topics related to AppGini Helper JavaScript Library, provided by bizzworxx as a third-party AppGini plugin.
Post Reply
User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

How to: Show/Hide custom message on checkbox-click

Post by jsetzer » 2020-02-28 11:33

Hi,

I have written a tutorial on this topic:
https://appgini.bizzworxx.de/appgini-he ... box-click/


This is the result:
Lr89xCLfTW.gif
Lr89xCLfTW.gif (12.49 KiB) Viewed 5965 times

This is the code you will need:

Code: Select all

// file: hooks/TABLENAME-dv.js
var fieldname = "int_checkbox";
var alert_message = "This is my custom message for the warning";
var alert_variation = Variation.Warning;

new AppGiniField(fieldname)
    .onChange(toggleAlert)
    .insertAfter().alert(alert_message, alert_variation, "alert-on-check hidden");

new AppGiniDetailView().ready(toggleAlertAfterLoad);

function toggleAlertAfterLoad() {

    // UPDATED 2020/03/03 JSE
    $j("#" + fieldname).closest(".checkbox").next().addClass("alert-on-check");

    var is_checked =  $j("#" + fieldname).attr("checked") !== undefined;
    toggleAlert(is_checked);
}

function toggleAlert(visible = true, className = "alert-on-check") {
    var alert = jQuery("." + className);
    if (!alert.length)
        console.error("Alert not found: ." + className);
    else {
        if (visible) {
            alert.removeClass("hidden");
        } else {
            alert.addClass("hidden");
        }
    }
}
Dynamically inserting certain elements before/after a field has been described here:
https://appgini.bizzworxx.de/products/j ... -elements/

I hope you like it and it will help you!

Best,
Jan
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

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

UPDATE: How to: Show/Hide custom message on checkbox-click

Post by jsetzer » 2020-03-03 07:05

For backward compatibility there is a small change required in toggleAlertAfterLoad-function. We need one additional line of code.

Please replace the function by the following:

Code: Select all

function toggleAlertAfterLoad() {
    $j("#" + fieldname).closest(".checkbox").next().addClass("alert-on-check");
    var is_checked =  $j("#" + fieldname).attr("checked") !== undefined;
    toggleAlert(is_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

Post Reply