Datetime def not working?
Datetime def not working?
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
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
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!
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
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/
This got stranger today, the calendar does not display years previous to 2010...
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
indatetime
, the default is 10,Colin
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.
I pulled the main HMTL and javascript configuration page and posted here:
http://live.datatables.net/nolefuqe/1/edit
We would really need to see the
def
failing. That code you posted doesn't run, and you havewhich 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
@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, };
}
in your field definition should do it. Here is a running example showing that: http://live.datatables.net/nuvihosi/79/edit .
Allan