refactor: Update TextInput validation to handle list values
This commit is contained in:
parent
32e5b6fe49
commit
0b91156b6c
1 changed files with 15 additions and 7 deletions
|
|
@ -57,9 +57,8 @@ class MessageInput(StrInput):
|
||||||
class TextInput(StrInput):
|
class TextInput(StrInput):
|
||||||
input_types: list[str] = ["Message"]
|
input_types: list[str] = ["Message"]
|
||||||
|
|
||||||
@field_validator("value")
|
@staticmethod
|
||||||
@classmethod
|
def _validate_value(v: Any, _info):
|
||||||
def validate_value(cls, v: Any, _info):
|
|
||||||
value = None
|
value = None
|
||||||
if isinstance(v, str):
|
if isinstance(v, str):
|
||||||
value = v
|
value = v
|
||||||
|
|
@ -76,10 +75,19 @@ class TextInput(StrInput):
|
||||||
f"You can set `text_key` to one of the following keys: {keys} or set the value using another Component."
|
f"You can set `text_key` to one of the following keys: {keys} or set the value using another Component."
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Invalid input type {type(v)}")
|
raise ValueError(f"Invalid value type {type(v)}")
|
||||||
if isinstance(value, str):
|
return value
|
||||||
return value
|
|
||||||
raise ValueError(f"Invalid value type {type(value)}")
|
@field_validator("value")
|
||||||
|
@classmethod
|
||||||
|
def validate_value(cls, v: Any, _info):
|
||||||
|
is_list = _info.data["is_list"]
|
||||||
|
value = None
|
||||||
|
if is_list:
|
||||||
|
value = [cls._validate_value(vv, _info) for vv in v]
|
||||||
|
else:
|
||||||
|
value = cls._validate_value(v, _info)
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
class MultilineInput(BaseInputMixin):
|
class MultilineInput(BaseInputMixin):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue