浏览代码

validate now returns a bool

Mathias G 1 年之前
父节点
当前提交
d1d4c4a5cd
共有 1 个文件被更改,包括 6 次插入5 次删除
  1. 6 5
      nicegui/elements/mixins/validation_element.py

+ 6 - 5
nicegui/elements/mixins/validation_element.py

@@ -15,16 +15,17 @@ class ValidationElement(ValueElement):
         """The latest error message from the validation functions."""
         return self._error
 
-    def validate(self) -> None:
+    def validate(self) -> bool:
         """Validate the current value and set the error message if necessary."""
         for message, check in self.validation.items():
             if not check(self.value):
                 self._error = message
                 self.props(f'error error-message="{message}"')
-                break
-        else:
-            self._error = None
-            self.props(remove='error')
+                return False
+
+        self._error = None
+        self.props(remove='error')
+        return True
 
     def _handle_value_change(self, value: Any) -> None:
         super()._handle_value_change(value)