Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form serialize #699

Merged
merged 5 commits into from
Dec 1, 2022
Merged

Form serialize #699

merged 5 commits into from
Dec 1, 2022

Conversation

acivitillo
Copy link
Contributor

@acivitillo acivitillo commented Mar 3, 2022

closes: #573

@rmorshea
Copy link
Collaborator

rmorshea commented Mar 5, 2022

I'll have time to take a look at this over the weekend

@acivitillo
Copy link
Contributor Author

acivitillo commented Mar 6, 2022

great, please note my PR testing case for json serialization of form is broken. I am sending you the diff to understand how you want to approach form serialization as form contains multiple elements

@rmorshea
Copy link
Collaborator

rmorshea commented Mar 6, 2022

@acivitillo, I've done a proper rebase with main and fixed up the serialization implementation. My understanding of how the elements attribute worked was a bit off. Also, here's some updated sample code for testing this out:

from idom import component, event, html, run


@component
def Form():

    @event(prevent_default=True)
    def handle_form(event):
        print(event["target"]["elements"])

    return html.form(
        {"onSubmit": handle_form},
        html.input({"name": "firstname"}),
        html.p("test"),
        html.button({"type": "submit", "value": "Submit"}, "Submit"),
        html.input({"lastname": "lastname"}),
        html.p("tes2t"),
    )


run(Form)

Note the prevent_default=True. Otherwise the page adds query parameters to the URL. IDOM interprets query parameters as keyword arguments to the root component. Not sure if that behavior should be removed when routing is introduced (cc: @Archmonger)?

Also, I changed html.input({"name": "name"}) to html.input({"name": "firstname"}), because child elements of a <form> get bound as attributes of that <form> under their name. Thus, attaching a form <input> name="name" caused a serialization issue which I handle (and note in a comment).

Could you address the tests given these changes? In addition to the elements attribute, I've serialized the name attribute too.

@Archmonger
Copy link
Contributor

Serializing form attributes into the URL would be a nice feature if we could get it working cleanly. Might help with form value persistence upon WS disconnect?

We should do some investigation later down the line to figure out what React apps typically do for forms.

@rmorshea
Copy link
Collaborator

rmorshea commented Nov 30, 2022

To properly handle form URLs we'll need a wrapper around the standard form element. Besides that, this PR works.

@Archmonger
Copy link
Contributor

What do we plan on doing about file fields

@rmorshea
Copy link
Collaborator

rmorshea commented Nov 30, 2022

Not entirely sure. We can address #574 in a different PR though.

Archmonger
Archmonger previously approved these changes Dec 1, 2022
temp.py Outdated Show resolved Hide resolved
@rmorshea rmorshea merged commit 98a3d1e into reactive-python:main Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Serialize Form Data
3 participants