Rohan Rao
Rohan Rao

Reputation: 2603

How to disable previous month in date-range picker

I am using JQuery DateRange Picker, and I am looking for disabling previous months i.e. Jan 2020, Dec 2019, Nov and so on..

Date Range Picker

I tried this:

<asp:TextBox ID="txtPunchDate" class="form-control" runat="server" autocomplete="off"></asp:TextBox>


 $('#<%= txtDate.ClientID%>').daterangepicker({
   locale: {
            format: 'YYYY-MM-DD',
            "separator": " to "
   },
   changeMonth: false,
   changeYear: false,
   stepMonths: 0
 });

But it doesn't seem to be working.. Nothing happens..

Can anybody help me here?

Upvotes: 2

Views: 1392

Answers (1)

Roko C. Buljan
Roko C. Buljan

Reputation: 206028

Add

minDate: moment().startOf('month'),

Example:

jQuery(function($) {

  $('input[name="daterange"]').daterangepicker({
    locale: {
      format: 'YYYY-MM-DD',
      "separator": " to "
    },
    minDate: moment().startOf('month'),
    changeMonth: false,
    changeYear: false,
    stepMonths: 0
  });

});
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />


<input type="text" name="daterange" />


<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>

Upvotes: 2

Related Questions