Nuju
Nuju

Reputation: 332

Hide year from the Bootstrap Datetimepicker

I have two bootstrap datetimepickers in a single page. One is to choose the year and the other to choose the month. I have managed these two via properties viewMode and format. See my two datetimepicker code below:

$('.datepickersren').datetimepicker({             
    format: "MMMM",
    viewMode: "months", 
})

$('.datepickers').datetimepicker({             
    format: "YYYY",
    viewMode: "years", 
})

I want to hide the year chooser if the viewMode: "months".

I have tried the below CSS code and it is working and this is what my exact requirement.

<style type="text/css">
.picker-switch{
    display: none !important;
}
.prev{
    display: none !important;
}
.next{
    display: none !important;
}
</style>

But the year chooser is hiding from the years picker also viewMode: "years". That should not happen.

Can I have the above CSS style for the months picker only? I mean if the viewMode is "months" (viewMode: "months").

Upvotes: 1

Views: 3772

Answers (1)

VincenzoC
VincenzoC

Reputation: 31502

You can limit your CSS selector adding .datepickersren before .picker-switch .prev and .next. This way your rules will apply only to pickers with the .datepickersren class.

Here a working sample:

$('.datepickersren').datetimepicker({             
    format: "MMMM",
    viewMode: "months", 
});

$('.datepickers').datetimepicker({             
    format: "YYYY",
    viewMode: "years", 
});
.datepickersren .picker-switch{
  display: none !important;
}
.datepickersren .prev{
  display: none !important;
}
.datepickersren .next{
  display: none !important;
}
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>

<div class="form-group">
    <div class="input-group date datepickersren">
        <input type='text' class="form-control"/>
        <span class="input-group-addon">
            <span class="glyphicon glyphicon-calendar"></span>
        </span>
    </div>
</div>
<div class="form-group">
    <div class="input-group date datepickers">
        <input type='text' class="form-control"/>
        <span class="input-group-addon">
            <span class="glyphicon glyphicon-calendar"></span>
        </span>
    </div>
</div>

Upvotes: 2

Related Questions