Explorar el Código

don't replace empty validation dicts with new instances (#2235)

Falko Schindler hace 1 año
padre
commit
7ec8b5e6d5

+ 1 - 1
nicegui/elements/input.py

@@ -44,7 +44,7 @@ class Input(ValidationElement, DisableableElement, component='input.js'):
         :param autocomplete: optional list of strings for autocompletion
         :param autocomplete: optional list of strings for autocompletion
         :param validation: dictionary of validation rules, e.g. ``{'Too long!': lambda value: len(value) < 3}``
         :param validation: dictionary of validation rules, e.g. ``{'Too long!': lambda value: len(value) < 3}``
         """
         """
-        super().__init__(value=value, on_value_change=on_change, validation=validation or {})
+        super().__init__(value=value, on_value_change=on_change, validation=validation)
         if label is not None:
         if label is not None:
             self._props['label'] = label
             self._props['label'] = label
         if placeholder is not None:
         if placeholder is not None:

+ 2 - 2
nicegui/elements/mixins/validation_element.py

@@ -5,9 +5,9 @@ from .value_element import ValueElement
 
 
 class ValidationElement(ValueElement):
 class ValidationElement(ValueElement):
 
 
-    def __init__(self, validation: Dict[str, Callable[..., bool]], **kwargs: Any) -> None:
+    def __init__(self, validation: Optional[Dict[str, Callable[..., bool]]], **kwargs: Any) -> None:
         super().__init__(**kwargs)
         super().__init__(**kwargs)
-        self.validation = validation
+        self.validation = validation if validation is not None else {}
         self._error: Optional[str] = None
         self._error: Optional[str] = None
 
 
     @property
     @property

+ 1 - 1
nicegui/elements/number.py

@@ -43,7 +43,7 @@ class Number(ValidationElement, DisableableElement):
         :param validation: dictionary of validation rules, e.g. ``{'Too large!': lambda value: value < 3}``
         :param validation: dictionary of validation rules, e.g. ``{'Too large!': lambda value: value < 3}``
         """
         """
         self.format = format
         self.format = format
-        super().__init__(tag='q-input', value=value, on_value_change=on_change, validation=validation or {})
+        super().__init__(tag='q-input', value=value, on_value_change=on_change, validation=validation)
         self._props['type'] = 'number'
         self._props['type'] = 'number'
         if label is not None:
         if label is not None:
             self._props['label'] = label
             self._props['label'] = label

+ 1 - 1
nicegui/elements/textarea.py

@@ -26,5 +26,5 @@ class Textarea(Input, component='input.js'):
         :param on_change: callback to execute when the value changes
         :param on_change: callback to execute when the value changes
         :param validation: dictionary of validation rules, e.g. ``{'Too long!': lambda value: len(value) < 3}``
         :param validation: dictionary of validation rules, e.g. ``{'Too long!': lambda value: len(value) < 3}``
         """
         """
-        super().__init__(label, placeholder=placeholder, value=value, on_change=on_change, validation=validation or {})
+        super().__init__(label, placeholder=placeholder, value=value, on_change=on_change, validation=validation)
         self._props['type'] = 'textarea'
         self._props['type'] = 'textarea'