jQuery UI Datepicker - Custom button - Custom text

10,501

Solution 1

Modified answer due to comment

You mean like this: http://jsfiddle.net/7Wygg/10/ ?

I just added

$(input).datepicker("hide");
$(input).val("custom text");

Solution 2

set a demo HERE and here in datepicker we can set date like pattern not any other

$(function() {
$(".datepicker").datepicker({
    showButtonPanel: true,
    beforeShow: function (input) {
        setTimeout(function () {
            var buttonPane = $(input)
                .datepicker("widget")
                .find(".ui-datepicker-buttonpane");

            var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Custom</button>');
            btn.unbind("click")
            .bind("click", function () {
                //$.datepicker._clearDate(input);
                alert('custom text');
                $(".datepicker").datepicker( "hide" );
                $( ".datepicker" ).datepicker( "setDate", "19/12/2003" );// here in cutom we can set date like pattern not any other

            });

            btn.appendTo(buttonPane);

        }, 1);
    }
});
});
Share:
10,501
FeKuLa
Author by

FeKuLa

Web developer

Updated on June 04, 2022

Comments

  • FeKuLa
    FeKuLa almost 2 years

    I need to add a custom button in jQuery UI Datepicker, and when the user clicks that button, set a value to input (a string of text) and close the popup. Is possible this?

    Fiddle example: http://jsfiddle.net/7Wygg/

    showButtonPanel: true,
    beforeShow: function (input) {
        setTimeout(function () {
            var buttonPane = $(input)
                .datepicker("widget")
                .find(".ui-datepicker-buttonpane");
    
            var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Custom</button>');
            btn.unbind("click")
            .bind("click", function () {
                //$.datepicker._clearDate(input);
                alert('custom text');
            });
    
            btn.appendTo(buttonPane);
    
        }, 1);
    }
    

    Thank you.