DateTime display() as an option

DateTime display() as an option

Loren MaxwellLoren Maxwell Posts: 469Questions: 114Answers: 10
edited October 15 in DateTime

For the DateTime plugin, display() is available through the api, but an option would be helpful as well.

{
    label: 'Some date field',
    name: 'some_date',
    type: 'datetime',
    opts: {
        display: {
            year: 1982,
            month: 10
        }
    }
},   

or maybe...

{
    label: 'Some date field',
    name: 'some_date',
    type: 'datetime',
    opts: {
        display: [1982, 10]
    }
},   

The display option would probably only take affect if there is no current value or default value set.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 65,347Questions: 1Answers: 10,841 Site admin

    Good idea! Added to the list :).

    Allan

  • Loren MaxwellLoren Maxwell Posts: 469Questions: 114Answers: 10
    edited November 3

    @allan -- just curious as to if this might be in the next version (1.6.2 or 1.7) of datetime.

    I have several pages that represent years and Editors for the tables on those pages.

    I don't want to set a default value because some of the dates will be unknown, but I'd like the calendar to be ready with the year set based on the page.

    Otherwise changing the year on the calendar from 2025 to 1982 or whatever adds a couple of clicks and a scroll through the years for each entry.

    I've tried to approach it this way:

    editor.on('open', function (e, mode, action) {
        var v = editor.val('game_date');
        if (!v || v === '' || v === null) {
            editor.val('game_date', '1982-10-01');
            editor.val('game_date', '');
        }
    });
    

    However the calendar reverts back to the current date (and the2025 year) on editor.val('game_date', '').

    Should I approach it differently? Or will you have the update done soon anyway?

  • allanallan Posts: 65,347Questions: 1Answers: 10,841 Site admin

    I hope so, but can't say for certain while it will be done. I'm currently focused on a major update in DataTables core.

    I don't know that there is a better option that getting it implemented I'm afraid.

    Allan

  • Loren MaxwellLoren Maxwell Posts: 469Questions: 114Answers: 10

    Ok, thanks -- and thanks for all the great support!

  • allanallan Posts: 65,347Questions: 1Answers: 10,841 Site admin
    Answer ✓

    Its been a funny old day here, so rather than trying to do a long period of focused work, I've been doing little bits and thought I'd look at this.

    I was midway through writing a reply saying it would be a bit tricky to do, when inspiration hit! I've just made this commit to add support for a display option on initialisation. Now if the field doesn't have a value then the picker will show that month / year. If it does have a value, then it displays that month / year of course.

    This is the option I went for:

            display: {
                year: 1982,
                month: 10
            }
    

    to match the display() return. Both properties are required.

    Allan

  • Loren MaxwellLoren Maxwell Posts: 469Questions: 114Answers: 10

    YAY! Looking forward to the release!

    Tiny improvements like this have HUGE impacts when doing hundreds or thousands of repetitive entries!

Sign In or Register to comment.