|
@@ -2,10 +2,10 @@ from typing import Any, Callable, Dict, List, Optional
|
|
|
|
|
|
from .icon import Icon
|
|
from .icon import Icon
|
|
from .mixins.disableable_element import DisableableElement
|
|
from .mixins.disableable_element import DisableableElement
|
|
-from .mixins.value_element import ValueElement
|
|
|
|
|
|
+from .mixins.validation_element import ValidationElement
|
|
|
|
|
|
|
|
|
|
-class Input(ValueElement, DisableableElement):
|
|
|
|
|
|
+class Input(ValidationElement, DisableableElement):
|
|
LOOPBACK = False
|
|
LOOPBACK = False
|
|
|
|
|
|
def __init__(self,
|
|
def __init__(self,
|
|
@@ -16,7 +16,7 @@ class Input(ValueElement, DisableableElement):
|
|
password_toggle_button: bool = False,
|
|
password_toggle_button: bool = False,
|
|
on_change: Optional[Callable[..., Any]] = None,
|
|
on_change: Optional[Callable[..., Any]] = None,
|
|
autocomplete: Optional[List[str]] = None,
|
|
autocomplete: Optional[List[str]] = None,
|
|
- validation: Optional[Dict[str, Callable[[Any], bool]]] = None) -> None:
|
|
|
|
|
|
+ validation: Dict[str, Callable[..., bool]] = {}) -> None:
|
|
"""Text Input
|
|
"""Text Input
|
|
|
|
|
|
This element is based on Quasar's `QInput <https://quasar.dev/vue-components/input>`_ component.
|
|
This element is based on Quasar's `QInput <https://quasar.dev/vue-components/input>`_ component.
|
|
@@ -37,7 +37,7 @@ class Input(ValueElement, DisableableElement):
|
|
:param autocomplete: optional list of strings for autocompletion
|
|
:param autocomplete: optional list of strings for autocompletion
|
|
:param validation: dictionary of validation rules, executed in dict order. e.g. ``{'Too long!': lambda value: len(value) < 3}``
|
|
:param validation: dictionary of validation rules, executed in dict order. e.g. ``{'Too long!': lambda value: len(value) < 3}``
|
|
"""
|
|
"""
|
|
- super().__init__(tag='q-input', value=value, on_value_change=on_change)
|
|
|
|
|
|
+ super().__init__(tag='q-input', 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:
|
|
@@ -52,9 +52,6 @@ class Input(ValueElement, DisableableElement):
|
|
self.props(f'type={"text" if is_hidden else "password"}')
|
|
self.props(f'type={"text" if is_hidden else "password"}')
|
|
icon = Icon('visibility_off').classes('cursor-pointer').on('click', toggle_type)
|
|
icon = Icon('visibility_off').classes('cursor-pointer').on('click', toggle_type)
|
|
|
|
|
|
- self.validation = validation or {}
|
|
|
|
- self._error: Optional[str] = None
|
|
|
|
-
|
|
|
|
if autocomplete:
|
|
if autocomplete:
|
|
def find_autocompletion() -> Optional[str]:
|
|
def find_autocompletion() -> Optional[str]:
|
|
if self.value:
|
|
if self.value:
|
|
@@ -75,18 +72,3 @@ class Input(ValueElement, DisableableElement):
|
|
|
|
|
|
self.on('keyup', autocomplete_input)
|
|
self.on('keyup', autocomplete_input)
|
|
self.on('keydown.tab', complete_input)
|
|
self.on('keydown.tab', complete_input)
|
|
-
|
|
|
|
- def on_value_change(self, value: Any) -> None:
|
|
|
|
- super().on_value_change(value)
|
|
|
|
- for message, check in self.validation.items():
|
|
|
|
- if not check(value):
|
|
|
|
- self._error = message
|
|
|
|
- self.props(f'error error-message="{message}"')
|
|
|
|
- break
|
|
|
|
- else:
|
|
|
|
- self.props(remove='error')
|
|
|
|
-
|
|
|
|
- @property
|
|
|
|
- def error(self) -> Optional[str]:
|
|
|
|
- """The latest error message from the validation functions."""
|
|
|
|
- return self._error
|
|
|