Refactor inputs.py to add MessageInput and TextInput classes
This commit is contained in:
parent
3ff0ac3a74
commit
c7a3624f21
2 changed files with 21 additions and 7 deletions
|
|
@ -17,12 +17,12 @@ from .inputs import (
|
|||
__all__ = [
|
||||
"SecretStrInput",
|
||||
"StrInput",
|
||||
"IntInput",
|
||||
"FloatInput",
|
||||
"BoolInput",
|
||||
"NestedDictInput",
|
||||
"DictInput",
|
||||
"DropdownInput",
|
||||
MultilineInput,
|
||||
NestedDictInput,
|
||||
PromptInput,
|
||||
SecretStrInput,
|
||||
StrInput,
|
||||
TextInput,
|
||||
"FileInput",
|
||||
"PromptInput",
|
||||
"MultilineInput",
|
||||
|
|
|
|||
|
|
@ -40,8 +40,22 @@ class StrInput(BaseInputMixin, ListableInputMixin, DatabaseLoadMixin): # noqa:
|
|||
"""Defines if the field will allow the user to open a text editor. Default is False."""
|
||||
|
||||
|
||||
class MessageInput(StrInput):
|
||||
input_types: list[str] = ["Message"]
|
||||
|
||||
@field_validator("value")
|
||||
@classmethod
|
||||
def validate_value(cls, v: Any, _info):
|
||||
# If v is a instance of Message, then its fine
|
||||
if isinstance(v, Message):
|
||||
return v
|
||||
if isinstance(v, str):
|
||||
return Message(text=v)
|
||||
raise ValueError(f"Invalid value type {type(v)}")
|
||||
|
||||
|
||||
class TextInput(StrInput):
|
||||
input_types: list[str] = ["Data", "Message", "Text"]
|
||||
input_types: list[str] = ["Message"]
|
||||
|
||||
@field_validator("value")
|
||||
@classmethod
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue