Paulo Honório
Paulo Honório

Reputation: 263

Bootstrap DatePicker format mm/yyyy set max month

I'm using bootstrap datepicker in format mm/yyyy, but I can't set max month. My code is like this:

$('#mesVigencia').datepicker({
    format: "mm/yyyy",
    startView: "months",
    minViewMode: "months",
    language: 'pt-BR'
});

How can I set max month like current month?

Upvotes: 1

Views: 2943

Answers (2)

Mohideen bin Mohammed
Mohideen bin Mohammed

Reputation: 20147

you need endDate: "0m" check my sample,

$('#mesVigencia').datepicker({
    format: "mm/yyyy",
    startView: "months",
    minViewMode: "months",
    language: 'pt-BR',
    endDate: "0m"
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker.css" rel="stylesheet"/>
<div id="mesVigencia"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.min.js"></script>

Upvotes: 1

void
void

Reputation: 36703

Use maxDate: in the object

$('#mesVigencia').datepicker({
    format: "mm/yyyy",
    startView: "months",
    minViewMode: "months",
    language: 'pt-BR',
    maxDate: new Date("2017-11-00")
});

Use new Date("2017-11-00") if you want to set november as the max month

Upvotes: 1

Related Questions