Page 1 of 1

Checkbox in Browse View

Posted: Sun Jun 23, 2024 12:39 am
by justme636
Hello there!

In one Browse view, I created an extra column with a check in Javascript/jQuery. All in all, it works fine, but there is a problem with ticking the checkbox; sometimes, it needs two or three quick clicks to get it activated, usually the same with deactivating the box. I got the impression, the checkbox sind not implemented properly and some elements/functions are in conflict with the checkbox.

Here are the codes from the Custom Code field:

Code: Select all

if (nuFormType() == 'browse') {
addCheckbox();
}

function nuSelectBrowse(element) {
    const col = $(element.target).attr('data-nu-column');
    if (col !== '0' && typeof col !== "undefined") {
        const primaryKey = $(element).attr('data-nu-primary-key');
        nuForm(nuFormId(), primaryKey, '', '', '1');
    } else {
        return false;
    }
}

function addCheckbox() {
$("[data-nu-column='0']").each(function(index) {
    let pk = $(this).attr('data-nu-primary-key');
    if (typeof pk !== "undefined") {
        let checked = $(this).html() == '1' ? 'checked="checked"': '';
        $(this).html('<input type="checkbox" ' + checked + ' id="' + pk + '" name="mycheckbox[]">')}
});
}
Does anyone have an idea why the checkbox can't get (de-)activated with a single click?

Re: Checkbox in Browse View

Posted: Sun Jun 23, 2024 6:34 am
by kev1n
Hi,

Change

Code: Select all

return false;
to

Code: Select all

return;
in you nuSelectBrowse()

Re: Checkbox in Browse View

Posted: Sun Jun 23, 2024 11:43 am
by justme636
Hi kev1n,

thank you, it works! Sometimes it is just a word too much...

Anyway, I use these functions to select rows in the browse view by clicking the checkbox and run a function for all selected rows. I think the principle of "select rows and do something with selected rows" is widely used. At least I know and appreciate it in several applications. Have you considered to implement it as a native function in nuBuilder?

Re: Checkbox in Browse View

Posted: Tue Jul 02, 2024 3:13 pm
by justme636
I opened another discussion about this in the Ideas & Suggestions subforum: viewtopic.php?t=12312

Re: Checkbox in Browse View

Posted: Mon Jul 08, 2024 8:08 am
by kev1n
Thank you for your suggestion. This will be evaluated, but we must consider that needs could vary and other requirements must be taken into account, such as "select all," "unselect all," dealing with multiple browse pages, running a function on a button click or when selected, etc.