Skip to content

Commit cb2ee61

Browse files
committed
improve(frontend): only trigger onblur when needed
1 parent fef9277 commit cb2ee61

File tree

7 files changed

+6237
-37
lines changed

7 files changed

+6237
-37
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ pywebio/html/js/pywebio.min.*
1111
/build
1212
/dist
1313
/*.egg-info
14-
/docs/_build
14+
/docs/_build
15+
/archive

docs/spec.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ The ``inputs`` field is a list of input items, each input item is a ``dict``, th
8080
* type: Input type, required.
8181
* name: Identifier of the input field, required.
8282
* onchange: bool, whether to push input value when input change
83+
* onbulr: bool, whether to push input value when input field `onblur`
8384
* auto_focus: Set focus automatically. At most one item of ``auto_focus`` can be true in the input item list
8485
* help_text: Help text for the input
8586
* Additional HTML attribute of the input element

pywebio/input.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,20 @@ def _parse_args(kwargs, excludes=()):
9797
"""
9898
kwargs = {k: v for k, v in kwargs.items() if v is not None and k not in excludes}
9999
assert is_html_safe_value(kwargs.get('name', '')), '`name` can only contains a-z、A-Z、0-9、_、-'
100+
100101
kwargs.update(kwargs.get('other_html_attrs', {}))
101102
kwargs.pop('other_html_attrs', None)
103+
104+
if kwargs.get('validate'):
105+
kwargs['onblur'] = True
102106
valid_func = kwargs.pop('validate', lambda _: None)
107+
103108
if kwargs.get('onchange'):
104109
onchange_func = kwargs['onchange']
105110
kwargs['onchange'] = True
106111
else:
107112
onchange_func = lambda _: None
113+
108114
return kwargs, valid_func, onchange_func
109115

110116

0 commit comments

Comments
 (0)