Skip to content

Commit 238aa0e

Browse files
robinkenwang0618
authored andcommitted
add datetime-local input type
1 parent b2d0b39 commit 238aa0e

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

pywebio/input.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,14 @@
9292
DATE = "date"
9393
TIME = "time"
9494
COLOR = "color"
95+
DATETIME_LOCAL = "datetime-local"
9596

9697
CHECKBOX = 'checkbox'
9798
RADIO = 'radio'
9899
SELECT = 'select'
99100
TEXTAREA = 'textarea'
100101

101-
__all__ = ['TEXT', 'NUMBER', 'FLOAT', 'PASSWORD', 'URL', 'DATE', 'TIME', 'COLOR', 'input', 'textarea', 'select',
102+
__all__ = ['TEXT', 'NUMBER', 'FLOAT', 'PASSWORD', 'URL', 'DATE', 'TIME', 'COLOR', 'DATETIME_LOCAL', 'input', 'textarea', 'select',
102103
'checkbox', 'radio', 'actions', 'file_upload', 'slider', 'input_group', 'input_update']
103104

104105

@@ -134,7 +135,7 @@ def input(label='', type=TEXT, *, validate=None, name=None, value=None, action=N
134135
r"""Text input
135136
136137
:param str label: Label of input field.
137-
:param str type: Input type. Currently, supported types are:`TEXT` , `NUMBER` , `FLOAT` , `PASSWORD` , `URL` , `DATE` , `TIME`, `COLOR`
138+
:param str type: Input type. Currently, supported types are:`TEXT` , `NUMBER` , `FLOAT` , `PASSWORD` , `URL` , `DATE` , `TIME`, `COLOR`, `DATETIME_LOCAL`
138139
139140
Note that `DATE` and `TIME` type are not supported on some browsers,
140141
for details see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Browser_compatibility
@@ -223,7 +224,7 @@ def select_date(set_value):
223224
item_spec, valid_func, onchange_func = _parse_args(locals(), excludes=('action',))
224225

225226
# check input type
226-
allowed_type = {TEXT, NUMBER, FLOAT, PASSWORD, URL, DATE, TIME, COLOR}
227+
allowed_type = {TEXT, NUMBER, FLOAT, PASSWORD, URL, DATE, TIME, COLOR, DATETIME_LOCAL}
227228
assert type in allowed_type, 'Input type not allowed.'
228229

229230
value_setter = None
@@ -722,7 +723,7 @@ def check_form(data):
722723

723724
if all('auto_focus' not in i for i in spec_inputs): # No `auto_focus` parameter is set for each input item
724725
for i in spec_inputs:
725-
text_inputs = {TEXT, NUMBER, PASSWORD, SELECT, URL, FLOAT, DATE, TIME}
726+
text_inputs = {TEXT, NUMBER, PASSWORD, SELECT, URL, FLOAT, DATE, TIME, DATETIME_LOCAL}
726727
if i.get('type') in text_inputs:
727728
i['auto_focus'] = True
728729
break

webiojs/src/models/input/input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const common_input_tpl = `
2828

2929

3030
export class Input extends InputItem {
31-
static accept_input_types: string[] = ["text", "password", "number", "float", "color", "date", "range", "time", "email", "url"];
31+
static accept_input_types: string[] = ["text", "password", "number", "float", "color", "date", "range", "time", "email", "url", "datetime-local"];
3232
previous_value = '';
3333

3434
constructor(spec: any, task_id: string, on_input_event: (event_name: string, input_item: InputItem) => void) {

0 commit comments

Comments
 (0)