Support

Account

Home Forums Backend Issues (wp-admin) How to trigger on close datepicker() event? Reply To: How to trigger on close datepicker() event?

  • Hey John, once again you’ve saved the day. 🙂

    This is what I ended up using. The setTimeout(). And added a check. I was not able to get the onSelect() to work 🙂

    With the code below I was even able to split the validation into two parts! One while editing and one post editing. Nice.

    $input.datepicker().on('input change select', function (e) {
            $this = this;
    
            // validate "live", directly on change
            // for example, if date end indeed is later than date start
            rtt_validate_datepicker_onChange($this, $input);
    
            // validate after exiting the field
            // for example, after populating start date AND exiting field, check if end date is empty, if so, than populate it with you desired value
            // Debounce
            setTimeout(function(){
                // check if your input is still focused. If so, it went back in editing.
                if ( ! $input.is(":focus")  ) {
                    // alright, after debounce it is blurred, not focused.
                    // That means we actually left the field. Now it's time for your validation.
                    rtt_validate_datepicker_onBlur($this, $input);
                }
            }, 300);
        });