Domanda

On Datepicker I can set a minDate and a maxDate. When i click in the selector it works fine in the calendar that appears.

But the user can type the date on the selector, and are able to put a date out of the range that I set.

If I press "ENTER" in the selector, it fix the date to the nearest date, but normally the user press "TAB", not "ENTER", so this fix don't happen.

Someone can help me how to trigger this "ENTER" when the user come out of my selector? My selector is a input[type=text].

function CarregaDatePicker() {
    dt_min = CampanhaDataInicio
    dt_max = CampanhaDataFim

    $("#data_nota").datepicker({
        minDate: dt_min,
        maxDate: dt_max,
        changeMonth: true,
        changeYear: true,
        monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
        monthNamesShort: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
        dayNamesMin: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S'],
        dayNames: ['Domingo', 'Segunda', 'Terça', 'Quarta', 'Quinta', 'Sexta', 'Sábado'],
        dateFormat: "dd/mm/yy"
    });
};

SOLUTION:

$("#data_nota").blur(function () {
    $(this).datepicker('setDate', $(this).datepicker('getDate'));
});
È stato utile?

Soluzione 2

$("#data_nota").blur(function () {
    $(this).datepicker('setDate', $(this).datepicker('getDate'));
});

Altri suggerimenti

Try

 $("#data_nota").blur(function(){
 $("#data_nota").datepicker({ minDate: dt_min, maxDate:dt_max});
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top