Răsfoiți Sursa

feat(#310): add color input type

wangweimin 3 ani în urmă
părinte
comite
3aa0bbca1a
2 a modificat fișierele cu 4 adăugiri și 3 ștergeri
  1. 3 2
      pywebio/input.py
  2. 1 1
      webiojs/src/models/input/input.ts

+ 3 - 2
pywebio/input.py

@@ -91,6 +91,7 @@ PASSWORD = "password"
 URL = "url"
 DATE = "date"
 TIME = "time"
+COLOR = "color"
 
 CHECKBOX = 'checkbox'
 RADIO = 'radio'
@@ -133,7 +134,7 @@ def input(label='', type=TEXT, *, validate=None, name=None, value=None, action=N
     r"""Text input
 
     :param str label: Label of input field.
-    :param str type: Input type. Currently supported types are:`TEXT` , `NUMBER` , `FLOAT` , `PASSWORD` , `URL` , `DATE` , `TIME`
+    :param str type: Input type. Currently, supported types are:`TEXT` , `NUMBER` , `FLOAT` , `PASSWORD` , `URL` , `DATE` , `TIME`, `COLOR`
 
        Note that `DATE` and `TIME` type are not supported on some browsers,
        for details see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Browser_compatibility
@@ -222,7 +223,7 @@ def input(label='', type=TEXT, *, validate=None, name=None, value=None, action=N
     item_spec, valid_func, onchange_func = _parse_args(locals(), excludes=('action',))
 
     # check input type
-    allowed_type = {TEXT, NUMBER, FLOAT, PASSWORD, URL, DATE, TIME}
+    allowed_type = {TEXT, NUMBER, FLOAT, PASSWORD, URL, DATE, TIME, COLOR}
     assert type in allowed_type, 'Input type not allowed.'
 
     value_setter = None

+ 1 - 1
webiojs/src/models/input/input.ts

@@ -11,7 +11,7 @@ const common_input_tpl = `
 <div class="form-group">
     {{#label}}<label for="{{id_name}}">{{label}}</label>{{/label}}
     {{#action}}<div class="input-group">{{/action}} 
-        <input type="{{type}}" id="{{id_name}}" aria-describedby="{{id_name}}_action_btn" list="{{id_name}}-list" class="form-control" >
+        <input type="{{type}}" id="{{id_name}}" aria-describedby="{{id_name}}_action_btn" {{#datalist}}list="{{id_name}}-list"{{/datalist}} class="form-control" >
         <datalist id="{{id_name}}-list">
             ${datalist_tpl}
         </datalist>