nes
nes

Reputation: 81

jQuery UI Datepicker - prevent refresh on date click

I changed year dropdown in Datepicker to textbox, because I want manual input for year.
But when I select some day, textbox returns to dropdown. How can I prevent that?

This is my fiddle:

HTML

<div id="datepicker"/>

jQuery

$("#datepicker").datepicker({
    changeMonth: true,
    changeYear: true,
    onSelect: function() {  
        $(this).data('datepicker').inline = true;      
        var curDate = $(this).datepicker('getDate');        
        var month = $(".ui-datepicker-month").val();
        var year = $(".ui-datepicker-month").next("input").val();
        $("#datepicker").datepicker('setDate', new Date(year, month, $.datepicker.formatDate('dd', curDate)));

                //var text = $("<input type='text'id = 'textbox' style='width:106px' value='2015'/>");
    //$(".ui-datepicker-year").before(text).hide();
    }        
});
var text = $("<input type='text'id = 'textbox' style='width:106px' value='2015'/>");
$(".ui-datepicker-year").before(text).hide();

Thanks in advance!

Upvotes: 1

Views: 1875

Answers (1)

J Santosh
J Santosh

Reputation: 3847

The option onSelect does some code execution after selecting date.

See the line $("#datepicker").datepicker('setDate', new Date(year, month, $.datepicker.formatDate('dd', curDate))); inside onSelect block.

there you are again assigning today's date . so just remove or comment it .

Fiddle

Upvotes: 1

Related Questions