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

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744946110a4602626.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信