How do I clear/reset the selected dates on the jQuery UI Datepicker calendar?

后端 未结 16 1586
感情败类
感情败类 2020-12-02 07:19

How do I reset the datepicker calendar values?.. The min and max date restrictions?

The problem is that when I clear the dates (by deleting the textbox values), th

相关标签:
16条回答
  • 2020-12-02 07:34

    My way to solve this problem

    Change var 'controls' on ui.js

    controls = (!inst.inline ? "<button type='button' class='ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all' data-handler='hide' data-event='click'>" +
            this._get(inst, "closeText") + "</button>" + "<button type='button' class='ui-datepicker-close ui-datepicker-clear ui-state-default ui-priority-primary ui-corner-all' data-handler='hide' data-event='click'>" +
            this._get(inst, "clearText") + "</button>" : "");
    

    Then add a clearText var

        this.regional[""] = { // Default regional settings
        closeText: "Done", // Display text for close link
        clearText: "Clear", // Display text for close link
        prevText: "Prev", // Display text for previous month link
    

    And before show function

    $(".i_date").datepicker
    (
        {
            beforeShow: function (input, inst)
            {
                setTimeout
                (
                    function () 
                    { 
                        $('.ui-datepicker-clear').bind('click', function() { $(input).val(''); });
                    }, 
                    0
                );
            }
        }
    );
    
    0 讨论(0)
  • 2020-12-02 07:35

    Try changing the clearing code to:

    $('#clearDates').on('click', function(){
        dates.attr('value', '');
        $("input[id$='dpFrom'], input[id$='dpTo']").datepicker( "option", "maxDate", null );
        $("input[id$='dpFrom'], input[id$='dpTo']").datepicker( "option", "minDate", null );
    });
    
    0 讨论(0)
  • 2020-12-02 07:36

    Try This, This Will Add Clear Button On Jquery Calender That Will Clear Date.

    $("#DateField").datepicker({
        showButtonPanel: true,
        closeText: 'Clear',
             onClose: function (dateText, inst) {
            if ($(window.event.srcElement).hasClass('ui-datepicker-close'))
            {
                document.getElementById(this.id).value = '';
            }
        }
    });
    
    0 讨论(0)
  • 2020-12-02 07:36

    A modified version of Leniel Macaferi's solution to account for the backspace key being a "page back" shortcut in IE8 when a text field does not have focus (which appears to be the case when datepicker is open).

    It also uses val() to clear the field since _clearDate(this) did not work for me.

    $("#clearDates").datepicker().keyup(function (e) {
        // allow delete key (46) to clear the field
        if (e.keyCode == 46)
            $(this).val("");
    
        // backspace key (8) causes 'page back' in IE8 when text field
        // does not have focus, Bad IE!!
        if (e.keyCode == 8)
            e.stopPropagation();
    });
    
    0 讨论(0)
  • 2020-12-02 07:38
    $("#datepicker").datepicker({            
            showButtonPanel: true,
            closeText: 'Clear', 
            onClose: function () {
                var event = arguments.callee.caller.caller.arguments[0];                
                if ($(event.delegateTarget).hasClass('ui-datepicker-close')) {
                    $(this).val('');
                }
            }
        });
    
    0 讨论(0)
  • 2020-12-02 07:40

    Please try this solution it will work properly as I have tried

    $('selector').datepicker('setStartDate', 0);
    
     $('selector').datepicker('setEndDate', 0);
    $('selector').datepicker('update');
    
    0 讨论(0)
提交回复
热议问题