Page 1 of 1

Check "checkbox" status.

Posted: 2022-09-26 15:51
by A Bindi
Hello,

I have a table called "users" with a column "deactivated" (integer managed with a checkbox) and a column "date_deactivation" (date): I would like to check that the operator can't save a record checking "deactivated" without fill the "date_deactivation".

Can solve using hooks ? :roll:

ALex.

Re: Check "checkbox" status.

Posted: 2022-09-27 11:44
by zibrahim
Hi ALex
You can try this...(file : hooks/users-dv.js)

Code: Select all

// pop up modal alert when checkbox checked without date
$j('#deactivated').on('change', function () {
    var dateVal = $j('#date_deactivation').val();
    var activeSts = $j(this).prop('checked');
    if (activeSts && !dateVal) {
        modal_window({
            message: '<div class="alert alert-danger">' + 'Please enter a date first' + '</div>',
            title: 'Error !',
            close: function () {
                $j("#deactivated").prop("checked", false);
                $j("#date_deactivation").focus();
                $j("#date_deactivation").parents('.form-group').addClass('has-error');
            },
        });
    }
});
Hope this works.

Re: Check "checkbox" status.

Posted: 2022-09-30 08:41
by A Bindi
Thank you zibrahim, great !

I will test immediately you JS and I’ll tell you.

ALex.