Add "falafel" custom date/time field type and widget
finally able to edit datetime fields, but feels like a lot of assumptions to make, just to determine time zone..so keeping naive UTC on the backend still, and naive local on the frontend in general this needs more polish, but is a start..
This commit is contained in:
parent
99065548ff
commit
a807a0f50c
6 changed files with 136 additions and 7 deletions
tailbone/static/js
|
@ -9,15 +9,55 @@ const TailboneTimepicker = {
|
|||
'placeholder="Click to select ..."',
|
||||
'icon-pack="fas"',
|
||||
'icon="clock"',
|
||||
':value="value ? parseTime(value) : null"',
|
||||
'hour-format="12"',
|
||||
'@input="timeChanged"',
|
||||
':time-formatter="formatTime"',
|
||||
'>',
|
||||
'</b-timepicker>'
|
||||
].join(' '),
|
||||
|
||||
props: {
|
||||
name: String,
|
||||
id: String
|
||||
}
|
||||
id: String,
|
||||
value: String,
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
formatTime(time) {
|
||||
if (time === null) {
|
||||
return null
|
||||
}
|
||||
|
||||
let h = time.getHours()
|
||||
let m = time.getMinutes()
|
||||
let s = time.getSeconds()
|
||||
|
||||
h = h < 10 ? '0' + h : h
|
||||
m = m < 10 ? '0' + m : m
|
||||
s = s < 10 ? '0' + s : s
|
||||
|
||||
return h + ':' + m + ':' + s
|
||||
},
|
||||
|
||||
parseTime(time) {
|
||||
|
||||
if (time.getHours) {
|
||||
return time
|
||||
}
|
||||
|
||||
let found = time.match(/^(\d\d):(\d\d):\d\d$/)
|
||||
if (found) {
|
||||
return new Date(null, null, null,
|
||||
parseInt(found[1]), parseInt(found[2]))
|
||||
}
|
||||
},
|
||||
|
||||
timeChanged(time) {
|
||||
this.$emit('input', time)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Vue.component('tailbone-timepicker', TailboneTimepicker)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue