0

i am using bootstrap date picker for my angular js project.

below is the HTML

my date picker documentation is as below date picker documentation

   <input type="text" placeholder="From Date" id="fromDate"
    ng-required="newcashbenifit.isFixedAmount == false"
   ng-disabled="newcashbenifit.isFixedAmount == true"
    class="form-control" name="from" autocomplete="off"
   ng-model="newcashbenifit.fromDate" autoclose="false"
   data-date-format="dd/MM/yyyy"  bs-datepicker />

date picker is loading and working well. but i need to modify this to show only month and years. (remove dates). how i do it.

kumara
  • 877
  • 4
  • 19
  • 43

2 Answers2

1

Add min-view="1" attribute:

Minimum allowed view - 0 | 1 | 2. 1 will only allow month selection.

  <input type="text" placeholder="From Date" id="fromDate"
   min-view="1"
   ng-required="newcashbenifit.isFixedAmount == false"
   ng-disabled="newcashbenifit.isFixedAmount == true"
   class="form-control" name="from" autocomplete="off"
   ng-model="newcashbenifit.fromDate" autoclose="false"
   data-date-format="dd/MM/yyyy"  bs-datepicker />

Demo Plunker

Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225
  • thank you very much maxim.. This is amazing. God MAXIM <3 – kumara May 20 '20 at 11:33
  • when i select month , i need to show last date of the month. currently it shows first day. do u have any idea ? – kumara May 20 '20 at 12:38
  • It does not support this behavior. When we talk about a month, it means the beginning of the month. So you you need to listen on `newcashbenifit.fromDate" ` modify it with `moment` lib for example: https://stackoverflow.com/questions/39267623/moment-js-get-first-and-last-day-of-current-month/39267750 – Maxim Shoustin May 20 '20 at 12:52
0

Use minViewMode:

$('#sandbox-container input').datepicker({
    minViewMode: 1
});

https://bootstrap-datepicker.readthedocs.io/en/latest/options.html#minviewmode

Shivaji Mutkule
  • 1,020
  • 1
  • 15
  • 28