Datetime def not working?

Datetime def not working?

bfarkasbfarkas Posts: 181Questions: 48Answers: 0

Is the datetime field not accepting the def input anymore, trying it a few ways and even with just copying from the example, it either errors, or I have to quote it out and then it just shows up as text in that field.
Trying to set the default for a date to be today-18 years so was aiming for something along moment().subtract(18, 'years')
but as I said even the function () { return new Date(); } doesn't seem to work. I went to the manual page on the inoput and don't see a def defined either.

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    It's working in this example here - that's the last release. If that doesn't help, could you link to your page, please, or update this example here to demonstrate the issue,

    Colin

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    Hmm, it does work in both places for me, just not in mine, so something is definitely up there.
    https://newyorklife.acms.com/pti62nkppw16/

    Here is a quick upload of it. Thoughts? The end goal is to get it set to be 18 years old from the current date.
    Thanks!

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    I took a look at the page - it's not loading due an error ("Uncaught SyntaxError: Unexpected token 'function'"), and it looks like the source is minimised so I can't read it. Could you take a look, please,

    Colin

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    Sorry about that, although that is similar to the error that is thrown when you go to click new when I try the def for datetime.
    I just updated and took a look and the page completes load now:
    https://newyorklife.acms.com/pti62nkppw16/

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    This got stranger today, the calendar does not display years previous to 2010...

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    I took another look. The table is empty, and pressing New gives an error. The code still looks minimised, so I can't debug. Could you unminimise it, please.

    The range of dates is set by opts.yearRange in datetime, the default is 10,

    Colin

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    Thanks for the year range will give that a try.
    The error is created from adding the date time def. when I remove it the table works as expected.

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    I pulled the main HMTL and javascript configuration page and posted here:
    http://live.datatables.net/nolefuqe/1/edit

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    We would really need to see the def failing. That code you posted doesn't run, and you have

                    "def":       function () { return new Date(); },
    

    which is the same as in the example that I posted before that works.

    Could you unminimise the code on your site, like I've asked before, as that would help us debug what you've got.

    Colin

  • komaljkomalj Posts: 1Questions: 0Answers: 0

    @colin I am using the similar way to set default value for date ( def being 14 days more than current date) but if i logged it the def contains empty function
    console log below -
    {def: ƒ (),
    format: "YYYY-MM-DD",
    label: "due",
    name: "due_date",
    type: "datetime"}

    Using a function to set date field for editor -
    function date_editor(title,field,format=DATE_FORMAT_DJANGO){
    return { type: "date", label: title, name: field,
    def: function () { return moment(moment().add(5,'d')).format(format); },
    format: format, };
    }

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
            def: function () {
              return moment(moment().add(5,'d')).format(format);
            },
    

    in your field definition should do it. Here is a running example showing that: http://live.datatables.net/nuvihosi/79/edit .

    Allan

This discussion has been closed.