From 7ec8b5e6d5e40cb5fec007710588d737606b4840 Mon Sep 17 00:00:00 2001 From: Falko Schindler Date: Mon, 25 Dec 2023 22:29:51 +0100 Subject: [PATCH] don't replace empty validation dicts with new instances (#2235) --- nicegui/elements/input.py | 2 +- nicegui/elements/mixins/validation_element.py | 4 ++-- nicegui/elements/number.py | 2 +- nicegui/elements/textarea.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nicegui/elements/input.py b/nicegui/elements/input.py index 178844a01..d409e1e89 100644 --- a/nicegui/elements/input.py +++ b/nicegui/elements/input.py @@ -44,7 +44,7 @@ def __init__(self, :param autocomplete: optional list of strings for autocompletion :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: self._props['label'] = label if placeholder is not None: diff --git a/nicegui/elements/mixins/validation_element.py b/nicegui/elements/mixins/validation_element.py index 1bda35dfa..dd5708c2a 100644 --- a/nicegui/elements/mixins/validation_element.py +++ b/nicegui/elements/mixins/validation_element.py @@ -5,9 +5,9 @@ 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) - self.validation = validation + self.validation = validation if validation is not None else {} self._error: Optional[str] = None @property diff --git a/nicegui/elements/number.py b/nicegui/elements/number.py index 776f81f24..d50debb50 100644 --- a/nicegui/elements/number.py +++ b/nicegui/elements/number.py @@ -43,7 +43,7 @@ def __init__(self, :param validation: dictionary of validation rules, e.g. ``{'Too large!': lambda value: value < 3}`` """ 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' if label is not None: self._props['label'] = label diff --git a/nicegui/elements/textarea.py b/nicegui/elements/textarea.py index 5a5e755a6..8ea0a8642 100644 --- a/nicegui/elements/textarea.py +++ b/nicegui/elements/textarea.py @@ -26,5 +26,5 @@ def __init__(self, :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}`` """ - 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'