最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Materializecss Date Picker only days in the past - Stack Overflow

programmeradmin2浏览0评论

I am trying to make a input field for the users birthday. For this I would like them to only select years in the past.

How do I achieve this? I tried entering a negative number in the selectYears property but no luck.

JSFIDDLE

HTML:

<div class="col s12">
   <label for="birthday">Birthday</label>
   <input id="birthday" value="{{ user.birthday }}" type="date" name="birthday" class="datepicker">
</div>

JavaScript:

$('.datepicker').pickadate(
{
   selectMonths: true,
   selectYears: -100
});

I am trying to make a input field for the users birthday. For this I would like them to only select years in the past.

How do I achieve this? I tried entering a negative number in the selectYears property but no luck.

JSFIDDLE

HTML:

<div class="col s12">
   <label for="birthday">Birthday</label>
   <input id="birthday" value="{{ user.birthday }}" type="date" name="birthday" class="datepicker">
</div>

JavaScript:

$('.datepicker').pickadate(
{
   selectMonths: true,
   selectYears: -100
});
Share Improve this question asked Nov 14, 2015 at 22:40 Trevi AwaterTrevi Awater 2,4072 gold badges33 silver badges55 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3
var d = new Date();
d.setFullYear( d.getFullYear() - 100 );
$('.datepicker').pickadate(
{
   selectMonths: true,
   selectYears: d,
   max: new Date()
});

This will actually give full list of 100 past years.

This is how you set the year:

var d = new Date();
d.setFullYear( d.getFullYear() - 100 );
$('.datepicker').pickadate(
{
   selectMonths: true,
   selectYears: true,
   min: d,
   max: new Date()
});

http://jsfiddle/rpu61tf2/3/

You set selectYears: true when you want to allow your users to select the years from a drop down

发布评论

评论列表(0)

  1. 暂无评论