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 datetime from 'tail.datetime';
import dateFormat from 'dateformat';
import { Utility } from '../../core/utility'; 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_UTIL_SELECTOR = 'input[type="date"], input[type="time"], input[type="datetime-local"]';
const DATEPICKER_INITIALIZED_CLASS = 'datepicker--initialized'; const DATEPICKER_INITIALIZED_CLASS = 'datepicker--initialized';
@ -64,6 +67,12 @@ export class Datepicker {
this.datepickerInstance.close(); 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() { destroy() {

3
package-lock.json generated
View File

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

View File

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

View File

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