Skip to content

Commit

Permalink
new: Add latest validation arguments from Textual to TextInput extens…
Browse files Browse the repository at this point in the history
…ion. (#80)
  • Loading branch information
dfrtz authored Feb 18, 2024
1 parent bb94923 commit dd07ade
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ generated-members=fset,fget
mixin-class-rgx=.*[Mm]ixin|.*Extension

[pylint.VARIABLES]
# The "id" variable is an attribute on Textual widgets, and should be allowed in subclasses to maintain parity.
allowed-redefined-builtins=id
# The "id" and "type" variables are attributes on some Textual widgets, and should be allowed in subclasses
# to maintain parity.
allowed-redefined-builtins=id,type
good-names=id

[isort]
Expand Down
23 changes: 22 additions & 1 deletion textology/widgets/_textual/_text_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,35 @@
from textual import events
from textual import widgets
from textual.suggester import Suggester
from textual.types import InputValidationOn
from textual.validation import Validator
from typing_extensions import Literal

from .._extensions import WidgetExtension

InputType = Literal["integer", "number", "text"]


class TextInput(WidgetExtension, widgets.Input):
"""An extended text input widget.
Renamed from "Input" to avoid conflicts with callback dependency types.
"""

def __init__( # pylint: disable=too-many-arguments
def __init__( # pylint: disable=too-many-arguments,too-many-locals
self,
value: str | None = None,
placeholder: str = "",
highlighter: Highlighter | None = None,
password: bool = False,
*,
restrict: str | None = None,
type: InputType = "text",
max_length: int = 0,
suggester: Suggester | None = None,
validators: Validator | Iterable[Validator] | None = None,
validate_on: Iterable[InputValidationOn] | None = None,
valid_empty: bool = False,
name: str | None = None,
id: str | None = None,
classes: str | None = None,
Expand All @@ -43,8 +52,15 @@ def __init__( # pylint: disable=too-many-arguments
placeholder: Optional placeholder text for the input.
highlighter: An optional highlighter for the input.
password: Flag to say if the field should obfuscate its content.
restrict: A regex to restrict character inputs.
type: The type of the input.
max_length: The maximum length of the input, or 0 for no maximum length.
suggester: Suggester associated with this input instance.
validators: An iterable of validators that the Input value will be checked against.
validate_on: Zero or more of the values "blur", "changed", and "submitted",
which determine when to do input validation. The default is to do
validation for all messages.
valid_empty: Empty values are valid.
name: Optional name for the input widget.
id: Optional ID for the widget.
classes: Optional initial classes for the widget.
Expand All @@ -58,8 +74,13 @@ def __init__( # pylint: disable=too-many-arguments
placeholder=placeholder,
highlighter=highlighter,
password=password,
restrict=restrict,
type=type,
max_length=max_length,
suggester=suggester,
validators=validators,
validate_on=validate_on,
valid_empty=valid_empty,
name=name,
id=id,
classes=classes,
Expand Down

0 comments on commit dd07ade

Please sign in to comment.