Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

year, year-month, year-month-day picker possibilities #145

Closed
nareshv opened this issue Jul 24, 2012 · 9 comments
Closed

year, year-month, year-month-day picker possibilities #145

nareshv opened this issue Jul 24, 2012 · 9 comments

Comments

@nareshv
Copy link

nareshv commented Jul 24, 2012

Given the way current datepicker is implemented. Its possible to have year picker, year-month picker along with the current date picker alone.

I've tried to do it automatically with parseDate, but didn't had success. So, this alternative version.

diff against current version is https://gist.github.com/3169847

Here is the code which shows the picker in action

<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="bootstrap-datepicker.js"></script>
<link rel="stylesheet" href="bootstrap.2.0.4.css">
<link rel="stylesheet" type="text/css" href="datepicker.css">
</head>
<body>
<div class="container">
<form class="form form-horizontal">
<input type="text" id="a" date-date-format="dd/mm/yyyy"/>
<input type="text" id="b" date-date-format="mm/yyyy"/>
<input type="text" id="c" date-date-format="yyyy"/>
</form>
</div>
<script type="text/javascript">
$('#a').datepicker({startView : 'month', format : 'dd/mm/yyyy', enableYearToMonth: true, enableMonthToDay : true});
$('#b').datepicker({startView : 'year', format : 'mm/yyyy', enableYearToMonth: true, enableMonthToDay : false});
$('#c').datepicker({startView : 'decade', format : 'yyyy', enableYearToMonth : false, enableMonthToDay : false,});
</script>
</body>
</html>

@cnlpete
Copy link

cnlpete commented Jul 28, 2012

+1

@bartoszkopinski
Copy link

I think I have a nice solution:

$('.monthpicker').datepicker({
  "format": "yyyy-mm",
  'startView': 1
}).on('changeMonth', function(e) {
  var dp = $(e.currentTarget).data('datepicker');
  dp.date = e.date;
  dp.setValue();
  dp.hide();
});

$('.yearpicker').datepicker({
  "format": "yyyy",
  'startView': 2
}).on('changeYear', function(e) {
  var dp = $(e.currentTarget).data('datepicker');
  dp.date = e.date;
  dp.setValue();
  dp.hide();
});

@xthiago
Copy link

xthiago commented Nov 9, 2012

@bartoszkopinski very nice! :)

@link82
Copy link

link82 commented Jan 11, 2013

Great! Thank you, I was stuck trying to dismiss the picker and update the value on month change.

👍

@eternicode
Copy link
Contributor

Latest datepicker has minViewMode and startView options, should be good for this.

@obuma-erp
Copy link

Hi, this solution is very good for selecting only yyyy-mm format, but if you need to change the selected month when you click again it show the month viewmode.

@gchjob
Copy link

gchjob commented Jan 4, 2016

@sidronsile 添加一个配置项即可: {minViewMode: 1},this is my solution:
$('.date-picker').datepicker({
format: "yyyy-mm",
minViewMode: 'months', // or 1, 月选择
startView: 'decade' // or 2, 10年选择
}).on('changeMonth', function(e) {
$(e.currentTarget).data('datepicker').hide();
});

@jitendraF5buddy
Copy link

its not working

@splashes
Copy link

Hi,
I was using minViewMode to select months as a range. For e.g., January - March. But as it is stated in docs as

The day is set to the 1st for “months”, and the month is set to January for “years”, the year is set to the first year from the decade for “decades”, and the year is set to the first from the millennium for “centuries” HERE

If we are using minViewMode for range, then i need to select from January - 1st to March - 31st. And not March 1st as it would select now.

Is there any option to change the selected date when using minViewMode?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants