Jacobian Jacobian - 2 months ago 26
Javascript Question

ExtJS: checkbox click or keyup event

Now I can handle

change
event of a
checkbox
in my
controller
. I do it like so:

"[itemId=TestCheckbox]": {
change: this.updateCheckbox
}


What I do not like about this, is that this event fires even when the state of the checkbox is changed programmatically - when, for example, the value is bound at the first time. All this results in unnecessary server requests:


  1. First request gets data from the server and binds the value to the checkbox

  2. Change event is fired and another server request is done



I do not like this. I want something like keyup event, or check event, so that I could trigger server request, only when the state of the checkbox is changed by hand and not programmatically.

Answer

You could try adding a mousedown/keydown handler to the checkbox el, then setting a flag there, and check for that flag in the change event handler

{
    xtype:     'checkboxfield',
    listeners: {
        mousedown: {
            element: 'el',
            fn:      function (e, el) {
                Ext.getCmp(e.currentTarget.id).myFlag = true
            }
        },
        change:    function (cb, newValue, oldValue, eOpts) {
            console.log(cb, cb.myFlag)
        }

    }
}
Comments