3

My Datetime picker works on the fist click, but if I click again in the input field again it shows the picker with the day field. How can I do this? Any help will be appreciated.

This is the image in first click (expected behavior)

enter image description here

This is the image in second click (expected behavior is to come like to the first one)

enter image description here

My code is below

HTML

<div class='input-group' id='dpRM'>
    <input type='text' class="form-control form-control-1 form-input input-sm fromq" placeholder="Enter Month and year" />
    <span class="input-group-addon">
        <span class="fa fa-calendar"></span>
    </span>
</div>

Javascript

<script type="text/javascript">
    $(function() {
        $('#dpRM').datetimepicker({
            format: "MMMM YYYY",
            viewMode: "years",
            //minViewMode: 0,
            toolbarPlacement: "top",
            allowInputToggle: true,
            icons: {
                time: 'fa fa-time',
                date: 'fa fa-calendar',
                up: 'fa fa-chevron-up',
                down: 'fa fa-chevron-down',
                previous: 'fa fa-chevron-left',
                next: 'fa fa-chevron-right',
                today: 'fa fa-screenshot',
                clear: 'fa fa-trash',
                close: 'fa fa-remove'
            }
        });
    });
</script>

Thanks in advance

niemmi
  • 17,113
  • 7
  • 35
  • 42
Bobin Thomas
  • 51
  • 1
  • 1
  • 3
  • 1
    This is a [known bug](https://github.com/Eonasdan/bootstrap-datetimepicker/issues/1850) affecting version `4.17.42` and `4.17.43`. You can modify datetimepicker code as suggested on github or use older version of the component like `4.17.37`. – VincenzoC Nov 03 '16 at 09:09
  • Thanks , That was a quick help but unfortunately it dint work for me, i am trying though – Bobin Thomas Nov 03 '16 at 11:30
  • commenting out currentViewMode = 0; worked for me in version 4.17.45 – JJ_Coder4Hire Oct 20 '17 at 20:25

1 Answers1

10

Try as follow

$('#dpRM').datetimepicker({
    viewMode : 'months',
    format : 'MM/YYYY',
    toolbarPlacement: "top",
    allowInputToggle: true,
    icons: {
        time: 'fa fa-time',
        date: 'fa fa-calendar',
        up: 'fa fa-chevron-up',
        down: 'fa fa-chevron-down',
        previous: 'fa fa-chevron-left',
        next: 'fa fa-chevron-right',
        today: 'fa fa-screenshot',
        clear: 'fa fa-trash',
        close: 'fa fa-remove'
    }
});

$("#dpRM").on("dp.show", function(e) {
   $(e.target).data("DateTimePicker").viewMode("months"); 
});

REF :: GitHub

R.Katnaan
  • 2,486
  • 4
  • 24
  • 36