refactor: Improve value validation in TextInput
This commit is contained in:
parent
ce415fc346
commit
4e13c7352d
1 changed files with 7 additions and 3 deletions
|
|
@ -47,13 +47,14 @@ class TextInput(StrInput):
|
||||||
@field_validator("value")
|
@field_validator("value")
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_value(cls, v: Any, _info):
|
def validate_value(cls, v: Any, _info):
|
||||||
|
value = None
|
||||||
if isinstance(v, str):
|
if isinstance(v, str):
|
||||||
return v
|
value = v
|
||||||
elif isinstance(v, Message):
|
elif isinstance(v, Message):
|
||||||
return v.text
|
value = v.text
|
||||||
elif isinstance(v, Data):
|
elif isinstance(v, Data):
|
||||||
if v.text_key in v.data:
|
if v.text_key in v.data:
|
||||||
return v.data[v.text_key]
|
value = v.data[v.text_key]
|
||||||
else:
|
else:
|
||||||
keys = ", ".join(v.data.keys())
|
keys = ", ".join(v.data.keys())
|
||||||
input_name = _info.data["name"]
|
input_name = _info.data["name"]
|
||||||
|
|
@ -63,6 +64,9 @@ class TextInput(StrInput):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Invalid input type {type(v)}")
|
raise ValueError(f"Invalid input type {type(v)}")
|
||||||
|
if isinstance(value, str):
|
||||||
|
return value
|
||||||
|
raise ValueError(f"Invalid value type {type(value)}")
|
||||||
|
|
||||||
|
|
||||||
class MultilineInput(BaseInputMixin):
|
class MultilineInput(BaseInputMixin):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue