|
@@ -7,25 +7,14 @@ from typing import Any, Dict, Literal, Optional, Union, overload
|
|
|
from reflex.vars import Var, BaseVar, ComputedVar
|
|
|
from reflex.event import EventChain, EventHandler, EventSpec
|
|
|
from reflex.style import Style
|
|
|
-from hashlib import md5
|
|
|
-from typing import Any, Dict, Iterator, Literal
|
|
|
-from jinja2 import Environment
|
|
|
+from typing import Any, Dict, Literal
|
|
|
from reflex.components.component import Component, ComponentNamespace
|
|
|
+from reflex.components.el.elements.forms import Form as HTMLForm
|
|
|
from reflex.components.radix.themes.components.text_field import TextFieldInput
|
|
|
-from reflex.components.tags.tag import Tag
|
|
|
-from reflex.constants.base import Dirs
|
|
|
from reflex.constants.event import EventTriggers
|
|
|
-from reflex.event import EventChain
|
|
|
-from reflex.utils import imports
|
|
|
-from reflex.utils.format import format_event_chain, to_camel_case
|
|
|
-from reflex.vars import BaseVar, Var
|
|
|
+from reflex.vars import Var
|
|
|
from .base import RadixPrimitiveComponentWithClassName
|
|
|
|
|
|
-FORM_DATA = Var.create("form_data")
|
|
|
-HANDLE_SUBMIT_JS_JINJA2 = Environment().from_string(
|
|
|
- "\n const handleSubmit_{{ handle_submit_unique_name }} = useCallback((ev) => {\n const $form = ev.target\n ev.preventDefault()\n const {{ form_data }} = {...Object.fromEntries(new FormData($form).entries()), ...{{ field_ref_mapping }}}\n\n {{ on_submit_event_chain }}\n\n if ({{ reset_on_submit }}) {\n $form.reset()\n }\n })\n "
|
|
|
-)
|
|
|
-
|
|
|
class FormComponent(RadixPrimitiveComponentWithClassName):
|
|
|
@overload
|
|
|
@classmethod
|
|
@@ -107,16 +96,81 @@ class FormComponent(RadixPrimitiveComponentWithClassName):
|
|
|
"""
|
|
|
...
|
|
|
|
|
|
-class FormRoot(FormComponent):
|
|
|
+class FormRoot(FormComponent, HTMLForm):
|
|
|
def get_event_triggers(self) -> Dict[str, Any]: ...
|
|
|
@overload
|
|
|
@classmethod
|
|
|
def create( # type: ignore
|
|
|
cls,
|
|
|
*children,
|
|
|
+ as_child: Optional[Union[Var[bool], bool]] = None,
|
|
|
+ accept: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ accept_charset: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ action: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ auto_complete: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ enc_type: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ method: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ name: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ no_validate: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ target: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
reset_on_submit: Optional[Union[Var[bool], bool]] = None,
|
|
|
handle_submit_unique_name: Optional[Union[Var[str], str]] = None,
|
|
|
- as_child: Optional[Union[Var[bool], bool]] = None,
|
|
|
+ access_key: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ auto_capitalize: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ content_editable: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ context_menu: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ dir: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ draggable: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ enter_key_hint: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ hidden: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ input_mode: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ item_prop: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ lang: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ role: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ slot: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ spell_check: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ tab_index: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ title: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
style: Optional[Style] = None,
|
|
|
key: Optional[Any] = None,
|
|
|
id: Optional[Any] = None,
|
|
@@ -180,9 +234,34 @@ class FormRoot(FormComponent):
|
|
|
|
|
|
Args:
|
|
|
*children: The children of the form.
|
|
|
+ as_child: Change the default rendered element for the one passed as a child.
|
|
|
+ accept: MIME types the server accepts for file upload
|
|
|
+ accept_charset: Character encodings to be used for form submission
|
|
|
+ action: URL where the form's data should be submitted
|
|
|
+ auto_complete: Whether the form should have autocomplete enabled
|
|
|
+ enc_type: Encoding type for the form data when submitted
|
|
|
+ method: HTTP method to use for form submission
|
|
|
+ name: Name of the form
|
|
|
+ no_validate: Indicates that the form should not be validated on submit
|
|
|
+ target: Where to display the response after submitting the form
|
|
|
reset_on_submit: If true, the form will be cleared after submit.
|
|
|
handle_submit_unique_name: The name used to make this form's submit handler function unique.
|
|
|
- as_child: Change the default rendered element for the one passed as a child.
|
|
|
+ access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
|
+ auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
|
+ content_editable: Indicates whether the element's content is editable.
|
|
|
+ context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
|
+ dir: Defines the text direction. Allowed values are ltr (Left-To-Right) or rtl (Right-To-Left)
|
|
|
+ draggable: Defines whether the element can be dragged.
|
|
|
+ enter_key_hint: Hints what media types the media element is able to play.
|
|
|
+ hidden: Defines whether the element is hidden.
|
|
|
+ input_mode: Defines the type of the element.
|
|
|
+ item_prop: Defines the name of the element for metadata purposes.
|
|
|
+ lang: Defines the language used in the element.
|
|
|
+ role: Defines the role of the element.
|
|
|
+ slot: Assigns a slot in a shadow DOM shadow tree to an element.
|
|
|
+ spell_check: Defines whether the element may be checked for spelling errors.
|
|
|
+ tab_index: Defines the position of the current element in the tabbing order.
|
|
|
+ title: Defines a tooltip for the element.
|
|
|
style: The style of the component.
|
|
|
key: A unique key for the component.
|
|
|
id: The id for the component.
|
|
@@ -743,9 +822,74 @@ class Form(FormRoot):
|
|
|
def create( # type: ignore
|
|
|
cls,
|
|
|
*children,
|
|
|
+ as_child: Optional[Union[Var[bool], bool]] = None,
|
|
|
+ accept: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ accept_charset: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ action: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ auto_complete: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ enc_type: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ method: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ name: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ no_validate: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ target: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
reset_on_submit: Optional[Union[Var[bool], bool]] = None,
|
|
|
handle_submit_unique_name: Optional[Union[Var[str], str]] = None,
|
|
|
- as_child: Optional[Union[Var[bool], bool]] = None,
|
|
|
+ access_key: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ auto_capitalize: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ content_editable: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ context_menu: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ dir: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ draggable: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ enter_key_hint: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ hidden: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ input_mode: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ item_prop: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ lang: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ role: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ slot: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ spell_check: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ tab_index: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ title: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
style: Optional[Style] = None,
|
|
|
key: Optional[Any] = None,
|
|
|
id: Optional[Any] = None,
|
|
@@ -809,9 +953,34 @@ class Form(FormRoot):
|
|
|
|
|
|
Args:
|
|
|
*children: The children of the form.
|
|
|
+ as_child: Change the default rendered element for the one passed as a child.
|
|
|
+ accept: MIME types the server accepts for file upload
|
|
|
+ accept_charset: Character encodings to be used for form submission
|
|
|
+ action: URL where the form's data should be submitted
|
|
|
+ auto_complete: Whether the form should have autocomplete enabled
|
|
|
+ enc_type: Encoding type for the form data when submitted
|
|
|
+ method: HTTP method to use for form submission
|
|
|
+ name: Name of the form
|
|
|
+ no_validate: Indicates that the form should not be validated on submit
|
|
|
+ target: Where to display the response after submitting the form
|
|
|
reset_on_submit: If true, the form will be cleared after submit.
|
|
|
handle_submit_unique_name: The name used to make this form's submit handler function unique.
|
|
|
- as_child: Change the default rendered element for the one passed as a child.
|
|
|
+ access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
|
+ auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
|
+ content_editable: Indicates whether the element's content is editable.
|
|
|
+ context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
|
+ dir: Defines the text direction. Allowed values are ltr (Left-To-Right) or rtl (Right-To-Left)
|
|
|
+ draggable: Defines whether the element can be dragged.
|
|
|
+ enter_key_hint: Hints what media types the media element is able to play.
|
|
|
+ hidden: Defines whether the element is hidden.
|
|
|
+ input_mode: Defines the type of the element.
|
|
|
+ item_prop: Defines the name of the element for metadata purposes.
|
|
|
+ lang: Defines the language used in the element.
|
|
|
+ role: Defines the role of the element.
|
|
|
+ slot: Assigns a slot in a shadow DOM shadow tree to an element.
|
|
|
+ spell_check: Defines whether the element may be checked for spelling errors.
|
|
|
+ tab_index: Defines the position of the current element in the tabbing order.
|
|
|
+ title: Defines a tooltip for the element.
|
|
|
style: The style of the component.
|
|
|
key: A unique key for the component.
|
|
|
id: The id for the component.
|
|
@@ -837,9 +1006,74 @@ class FormNamespace(ComponentNamespace):
|
|
|
@staticmethod
|
|
|
def __call__(
|
|
|
*children,
|
|
|
+ as_child: Optional[Union[Var[bool], bool]] = None,
|
|
|
+ accept: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ accept_charset: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ action: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ auto_complete: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ enc_type: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ method: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ name: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ no_validate: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ target: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
reset_on_submit: Optional[Union[Var[bool], bool]] = None,
|
|
|
handle_submit_unique_name: Optional[Union[Var[str], str]] = None,
|
|
|
- as_child: Optional[Union[Var[bool], bool]] = None,
|
|
|
+ access_key: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ auto_capitalize: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ content_editable: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ context_menu: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ dir: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ draggable: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ enter_key_hint: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ hidden: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ input_mode: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ item_prop: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ lang: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ role: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ slot: Optional[Union[Var[Union[str, int, bool]], Union[str, int, bool]]] = None,
|
|
|
+ spell_check: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ tab_index: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
+ title: Optional[
|
|
|
+ Union[Var[Union[str, int, bool]], Union[str, int, bool]]
|
|
|
+ ] = None,
|
|
|
style: Optional[Style] = None,
|
|
|
key: Optional[Any] = None,
|
|
|
id: Optional[Any] = None,
|
|
@@ -903,9 +1137,34 @@ class FormNamespace(ComponentNamespace):
|
|
|
|
|
|
Args:
|
|
|
*children: The children of the form.
|
|
|
+ as_child: Change the default rendered element for the one passed as a child.
|
|
|
+ accept: MIME types the server accepts for file upload
|
|
|
+ accept_charset: Character encodings to be used for form submission
|
|
|
+ action: URL where the form's data should be submitted
|
|
|
+ auto_complete: Whether the form should have autocomplete enabled
|
|
|
+ enc_type: Encoding type for the form data when submitted
|
|
|
+ method: HTTP method to use for form submission
|
|
|
+ name: Name of the form
|
|
|
+ no_validate: Indicates that the form should not be validated on submit
|
|
|
+ target: Where to display the response after submitting the form
|
|
|
reset_on_submit: If true, the form will be cleared after submit.
|
|
|
handle_submit_unique_name: The name used to make this form's submit handler function unique.
|
|
|
- as_child: Change the default rendered element for the one passed as a child.
|
|
|
+ access_key: Provides a hint for generating a keyboard shortcut for the current element.
|
|
|
+ auto_capitalize: Controls whether and how text input is automatically capitalized as it is entered/edited by the user.
|
|
|
+ content_editable: Indicates whether the element's content is editable.
|
|
|
+ context_menu: Defines the ID of a <menu> element which will serve as the element's context menu.
|
|
|
+ dir: Defines the text direction. Allowed values are ltr (Left-To-Right) or rtl (Right-To-Left)
|
|
|
+ draggable: Defines whether the element can be dragged.
|
|
|
+ enter_key_hint: Hints what media types the media element is able to play.
|
|
|
+ hidden: Defines whether the element is hidden.
|
|
|
+ input_mode: Defines the type of the element.
|
|
|
+ item_prop: Defines the name of the element for metadata purposes.
|
|
|
+ lang: Defines the language used in the element.
|
|
|
+ role: Defines the role of the element.
|
|
|
+ slot: Assigns a slot in a shadow DOM shadow tree to an element.
|
|
|
+ spell_check: Defines whether the element may be checked for spelling errors.
|
|
|
+ tab_index: Defines the position of the current element in the tabbing order.
|
|
|
+ title: Defines a tooltip for the element.
|
|
|
style: The style of the component.
|
|
|
key: A unique key for the component.
|
|
|
id: The id for the component.
|