JQuery Datepicker, can't trigger onSelect event manually!

前端 未结 9 1036
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-05 00:00

I am using jquery\'s datepicker where a list of items is populated from an ajax call whenever a date is picked from an inline datepicker object. The script works perfect exc

9条回答
  •  粉色の甜心
    2021-01-05 00:29

    The accepted answer was not something I could use, because I was using common code that added hotkey functionality on all datepickers in my web application (to set value to today, +1 day, +1 month, etc.), and wanted to make sure onselect was called to validate the date value that was calculated with the hot key.

    I took this from the source code of the datepicker.js file. Note thiat this should be replaced with your datepicker element. In my case, I was calling this from a keydown event.

    // this is SUCH a hack.  We need to call onselect to call any
    // specific validation on this input.  I stole this from the datepicker source code.
    var inst = $.datepicker._getInst(this),
    onSelect = $.datepicker._get(inst, "onSelect");
    if (onSelect) {
        dateStr = $.datepicker._formatDate(inst);
        onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);
    }
    

提交回复
热议问题