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

javascript - Bulma calendar date input does not show the pre-populated start date - Stack Overflow

programmeradmin3浏览0评论

I am trying implement Bulma calendar in my project and I have a difficult setting a default start date.

I am doing the following as per documentation.

<input type="date" data-start-date="10/24/2019">

The date shows up fine when the date picker is open:

However, it does not show up in the input to begin with:

Minimum boilerplate is here: Codepen

I am trying implement Bulma calendar in my project and I have a difficult setting a default start date.

I am doing the following as per documentation.

<input type="date" data-start-date="10/24/2019">

The date shows up fine when the date picker is open:

However, it does not show up in the input to begin with:

Minimum boilerplate is here: Codepen

Share Improve this question asked Oct 24, 2019 at 11:59 JacobdoJacobdo 2,0333 gold badges24 silver badges42 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Try it like this:

HTML:

<input type="date" />

JS:

// Initialize all input of type date
var calendars = bulmaCalendar.attach('[type="date"]', {startDate: new Date('10/24/2019')});

// Loop on each calendar initialized
for(var i = 0; i < calendars.length; i++) {
    // Add listener to date:selected event
    calendars[i].on('select', date => {
        console.log(date);
    });
}

// To access to bulmaCalendar instance of an element
var element = document.querySelector('#my-element');
if (element) {
    // bulmaCalendar instance is available as element.bulmaCalendar
    element.bulmaCalendar.on('select', function(datepicker) {
        console.log(datepicker.data.value());
    });
}

Use the "value" attribute, e.g. date today Feb.26, 2021

<input type="date" value="2021-02-26">
发布评论

评论列表(0)

  1. 暂无评论