diff --git a/src/reactpy_django/forms/components.py b/src/reactpy_django/forms/components.py index 12fc767c..e468b362 100644 --- a/src/reactpy_django/forms/components.py +++ b/src/reactpy_django/forms/components.py @@ -14,9 +14,10 @@ convert_html_props_to_reactjs, convert_textarea_children_to_prop, ensure_input_elements_are_controlled, + intercept_anchor_links, set_value_prop_on_select_element, ) -from reactpy_django.forms.utils import convert_boolean_fields, convert_choice_fields +from reactpy_django.forms.utils import convert_boolean_fields, convert_multiple_choice_fields if TYPE_CHECKING: from collections.abc import Sequence @@ -79,7 +80,7 @@ def on_submit(_event): last_changed.set_current(timezone.now()) def on_submit_callback(new_data: dict[str, Any]): - convert_choice_fields(new_data, initialized_form) + convert_multiple_choice_fields(new_data, initialized_form) convert_boolean_fields(new_data, initialized_form) # TODO: ReactPy's use_state hook really should be de-duplicating this by itself. Needs upstream fix. @@ -95,6 +96,7 @@ async def on_change(_event): convert_textarea_children_to_prop, set_value_prop_on_select_element, ensure_input_elements_are_controlled(on_change), + intercept_anchor_links, strict=False, ) diff --git a/src/reactpy_django/forms/transforms.py b/src/reactpy_django/forms/transforms.py index 69c29fb0..47822a97 100644 --- a/src/reactpy_django/forms/transforms.py +++ b/src/reactpy_django/forms/transforms.py @@ -9,12 +9,9 @@ # TODO: Move all this logic to `reactpy.utils._mutate_vdom()` and remove this file. -UNSUPPORTED_PROPS = {"children", "ref", "aria-*", "data-*"} - def convert_html_props_to_reactjs(vdom_tree: VdomDict) -> VdomDict: """Transformation that standardizes the prop names to be used in the component.""" - if not isinstance(vdom_tree, dict): return vdom_tree @@ -38,7 +35,7 @@ def convert_textarea_children_to_prop(vdom_tree: VdomDict) -> VdomDict: text_content = vdom_tree.pop("children") text_content = "".join([child for child in text_content if isinstance(child, str)]) default_value = vdom_tree["attributes"].pop("defaultValue", "") - vdom_tree["attributes"]["value"] = text_content or default_value + vdom_tree["attributes"]["defaultValue"] = text_content or default_value for child in vdom_tree.get("children", []): convert_textarea_children_to_prop(child) @@ -46,61 +43,105 @@ def convert_textarea_children_to_prop(vdom_tree: VdomDict) -> VdomDict: return vdom_tree -def _find_selected_options(vdom_tree: VdomDict, mutation: Callable) -> list[VdomDict]: - """Recursively iterate through the tree of dictionaries to find an