feat(datepicker): format time on submit

This commit is contained in:
Sarah Vaupel 2019-08-12 13:49:57 +02:00
parent 0e5707ac9f
commit 9f8749c4ce
4 changed files with 12 additions and 3 deletions

View File

@ -1,6 +1,9 @@
import datetime from 'tail.datetime';
import dateFormat from 'dateformat';
import { Utility } from '../../core/utility';
const FORM_DATE_FORMAT = 'yyyy-mm-dd"T"HH:MM:ss';
const DATEPICKER_UTIL_SELECTOR = 'input[type="date"], input[type="time"], input[type="datetime-local"]';
const DATEPICKER_INITIALIZED_CLASS = 'datepicker--initialized';
@ -64,6 +67,12 @@ export class Datepicker {
this.datepickerInstance.close();
}
});
// format the dates before submission
element.form.addEventListener('submit', () => {
if (!this.datepickerInstance.select) return;
element.value = dateFormat(this.datepickerInstance.select, FORM_DATE_FORMAT);
});
}
destroy() {

3
package-lock.json generated
View File

@ -4794,8 +4794,7 @@
"dateformat": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz",
"integrity": "sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==",
"dev": true
"integrity": "sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q=="
},
"debug": {
"version": "2.6.9",

View File

@ -89,6 +89,7 @@
"webpack-cli": "^3.3.4"
},
"dependencies": {
"dateformat": "^3.0.3",
"flatpickr": "^4.5.7",
"npm": "^6.10.3",
"tail.datetime": "git+https://git@github.com/pytesNET/tail.DateTime.git#master"

View File

@ -811,7 +811,7 @@ localTimeField = Field
where
fieldTimeFormat :: String
--fieldTimeFormat = "%e.%m.%y %k:%M"
fieldTimeFormat = "%Y-%m-%dT%H:%M"
fieldTimeFormat = "%Y-%m-%dT%H:%M:%S"
-- `defaultTimeLocale` is okay here, since `fieldTimeFormat` does not contain any
readTime :: Text -> Either UniWorXMessage LocalTime