-
Prior to the new plugin system, we were able to set date formats on a per-instance level using inputFormat and inputParse in the hooks section of the options: $('dateField1').tempusDominus({
hooks: {
inputFormat: (context, date) => { return moment(date).format('MM/DD/YYYY'); },
inputParse: (context, value) => { return moment(value, 'MM/DD/YYYY').toDate(); }
}
});
$('dateField2').tempusDominus({
hooks: {
inputFormat: (context, date) => { return moment(date).format('MM/YYYY'); },
inputParse: (context, value) => { return moment(value, 'MM/YYYY').toDate(); }
}
}); Now that hooks have been removed from the options there is no way to set formatting except globally using the extend method on the module itself: <script src="/path/to/plugin.js"></script>
tempusDominus.extend(tempusDominus.plugins.moment_parse, 'MM/DD/YYYY');
$('dateField1').tempusDominus({
// how to change the format?
});
$('dateField2').tempusDominus({
// how to change the format?
}); This makes it impossible to have 2 fields on the same page with separate date formats (for example, one field with a full date and another with just month and year). The plugin documentation states that this should be possible, but I don't see how:
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 7 replies
-
You can still do the same thing per picker if you want const td = new tempusDominus.TempusDominus(
document.getElementById('datetimepicker1'),
{
//put your config here
}
);
td.dates.formatInput = function(date) { {return moment(date).format('MM/DD/YYYY') } } |
Beta Was this translation helpful? Give feedback.
-
Got it. Thanks. Can this be added to the docs? |
Beta Was this translation helpful? Give feedback.
-
Yes. I was just doing that 😁. |
Beta Was this translation helpful? Give feedback.
-
Hi I'm confused as well, I want to set the formatting but I can't see how currently I'm using the jquery plugin.
But yeah, I can't do it that way? |
Beta Was this translation helpful? Give feedback.
-
We need to check if the input is empty:
|
Beta Was this translation helpful? Give feedback.
-
this keeps being a problem for us when we moved the formatting/parsing hooks from the config to a plugin system 1> class level is absolute no go for us, because formatting/parsing is instances specific. we would leak stuff 2> instance level has this problem: Error: TD: Could not correctly parse "19-03-2006 18:00" to a date for input. because we can only initialized the parse/format after we already have the instance:
but the constructor already tries to parse stuff. but i couldn't have set it yet.. If i could just push the formatting as before with the "this.config" all problems would be gone.. Now i really need to work around it by making sure the input doesn't have a value yet and so on, which are all hacks and workaround around the problem that we cant initialize, configure a instance of the picker correctly at construction time. |
Beta Was this translation helpful? Give feedback.
-
I'm working on a complete and better solution to this. I put a lot of work into emulating some stuff that dayjs is doing. Please see this ticket for more info. #2537 |
Beta Was this translation helpful? Give feedback.
You can still do the same thing per picker if you want