FeKuLa
FeKuLa

Reputation: 402

jQuery UI Datepicker - Custom button - Custom text

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.

Upvotes: 2

Views: 11184

Answers (2)

Rob
Rob

Reputation: 919

Modified answer due to comment

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

I just added

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

Upvotes: 7

Rituraj ratan
Rituraj ratan

Reputation: 10388

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);
    }
});
});

Upvotes: 2

Related Questions