lundi 10 juin 2019

Can I use .trigger("change") in order to update a checkbox prior to the event handler finishing?

Basically, I have a grid that contains a bunch of items, and all of these items contain a checkbox to the left. These checkboxes are bound to a function I called ecuDataBound(), which contains event handlers that call a function called onChangeECU. I've noticed that the state of a checkbox being activated isn't done until after the event handler finishes running in its entirety - I'm wondering if there's a way to change the state of the checkbox prematurely.

Specifically, I read something about a .trigger("change") function that might be what I'm looking for, but I'm not sure I'm using it correctly or for the correct problem.

function ecuDataBound() {
    $('#ECUs .k-checkbox:not(:first)').on('click', onChangeECU);
}

function onChangeECU(arg) {
    // ...
    grid.trigger("change");
    isSelected = checkForSelection("#ECUs");
    // ...
}

function checkForSelection(gridID) {
    const inputString = gridID + " tr.k-state-selected";
    const isSelected = $(inputString).length;
    if (isSelected) {
        return true;
    }

Because the state of the checkboxes isn't updated until its event handler is completely done running, the function checkForSelection doesn't work as intended for the first run through. Can I use .trigger("change") in this context or am I thinking about this the wrong way?

Please let me know if I have worded this in a confusing way and if I need to elaborate on any more details. Thanks!




Aucun commentaire:

Enregistrer un commentaire