简体   繁体   English

如何在Material-Datetime-Picker中设置自己的默认日期

[英]How To Set Own Default Date In Material-Datetime-Picker

Here i am using Material-datetime-picker . 在这里,我正在使用Material-datetime-picker but i need only Date for DOB(Date Of Birth). 但是我只需要DOB(出生日期)的日期。 therefore on initial time Default Date should be from 1990 What Changing Should i Apply In material-datetime-picker.js 因此,在初始时间,默认日期应为1990年,我应该对material-datetime-picker.js应用哪些更改

index.php 的index.php

var picker = new MaterialDatetimePicker({})

  .on('submit', function(d) {
    var dt = d.format("DD/MM/YYYY");
    $("#dob").val(dt);
  });

$('#dob').click(function () {

picker.open();

});

replace Code in material-datetime-picker.js 替换material-datetime-picker.js中的代码

if (!this.value) {
    // TODO hack
    // set/setDate/setTime need refactoring to have single concerns
    // (set: set the value; setDate/setTime rename to renderDate/renderTime
    //  and deal with updating the view only).
    // For now this allows us to set the default time using the same quantize
    // rules as setting the date explicitly. Setting this.value meets setTime|Date's
    // expectation that we have a value, and `0` guarantees that we will detect
    this.value = moment(0);
    this.setDate(this.options.default);
    this.setTime(this.options.default);
  } else {
    this.setDate(this.value);
    this.setTime(this.value);
  }

To

if (!this.value) {
    // TODO hack
    // set/setDate/setTime need refactoring to have single concerns
    // (set: set the value; setDate/setTime rename to renderDate/renderTime
    //  and deal with updating the view only).
    // For now this allows us to set the default time using the same quantize
    // rules as setting the date explicitly. Setting this.value meets setTime|Date's
    // expectation that we have a value, and `0` guarantees that we will detect
    this.value = moment(0);
    this.setDate("12/12/1992");
    this.setTime(this.options.default);
  } else {
    this.setDate(this.value);
    this.setTime(this.value);
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Angular 材料日期时间选择器格式化日期 - How to format date with Angular material datetime picker 日期时间选择器中未设置默认值 - Default value is not set in datetime picker 如何在 angular 中设置日期选择器的默认范围 - How to set default range of date picker in angular Bootstrap Datetime选择器动态默认日期不起作用 - Bootstrap Datetime picker dynamic default date not working 如何默认为Material UI日期时间选择器的当前UTC日期/时间 - How to default to current UTC date/time for Material UI date time picker 如何在 material-ui 中为当前日期和时间的文本字段类型 datetime-local 设置默认值? - how can I set the default value to the textfield type datetime-local in material-ui for the current date and time? 如何在角矩选择器中将今天的日期和时间设置为默认值 - How to set today date and time as default in angular-moment-picker Angular 材料日期选择器设置为用作日期或月份 - Angular Material date picker set to use as date or month 如何自定义角度材料日期选择器? - How to Customise the angular material date-picker? 如何为反应的材料选择器实现默认工具栏? - How to implement default toolbar for material picker for react?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM