Răsfoiți Sursa

maint: check the return value of `validate` function for input group

wangweimin 3 ani în urmă
părinte
comite
19bd3d85f5
1 a modificat fișierele cu 6 adăugiri și 1 ștergeri
  1. 6 1
      pywebio/io_ctrl.py

+ 6 - 1
pywebio/io_ctrl.py

@@ -334,7 +334,12 @@ def input_event_handle(item_valid_funcs, form_valid_funcs, preprocess_funcs, onc
                     v_res = form_valid_funcs(data)
                     if v_res is not None:
                         all_valid = False
-                        onblur_name, error_msg = v_res
+                        try:
+                            onblur_name, error_msg = v_res
+                        except Exception:
+                            raise ValueError("The `validate` function for input group must "
+                                             "return `(name, error_msg)` when validation failed.")
+
                         send_msg('update_input', dict(target_name=onblur_name, attributes={
                             'valid_status': False,
                             'invalid_feedback': error_msg