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

Cannot read multi-part form data (fields and uploads) after submit #76

Open
taublast opened this issue Aug 5, 2024 · 4 comments
Open

Comments

@taublast
Copy link
Contributor

taublast commented Aug 5, 2024

The question was raised here how to acquire form content without hydro bind, the actual answer was that it is for now not possible.

For my app that was a stopper, it requires to read multi-part form data: fields along with uploads.

Hydro core is already ready to support that with a really small addition.

Solved this in my fork, will add a PR for the ability to send/read/bind/validate multi-part form data upon submit.

@kjeske
Copy link
Contributor

kjeske commented Aug 6, 2024

Hydro used to have it but I removed it to keep consistency with Bind lifecycle, which means that I wanted users to be able to control updating of the fields when it happens. If we wanted to support sending the fields on submit it would have to be an additional flag on hydro-on attribute, like:

<form hydro-on:submit="(() => Model.Save())" hydro-attach-form />

But then Bind lifecycle might not work correctly, because of many edge cases, so it would have to be omitted.

Btw have you seen the docs about file upload in Hydro?

@taublast
Copy link
Contributor Author

taublast commented Aug 6, 2024

Why whould sending the from break Bind lifecycle? Would you consider that feature if it would not break anything existing?

For the current use case, I am not building app it from scratch, but adapting existing forms and do not have the time to rewrite everything to use bindings. It's much faster to continue processing form data while enjoying Hydro.

@kjeske
Copy link
Contributor

kjeske commented Aug 9, 2024

There were some edge-cases, like:

  • Bind method triggered side-effects (via Dispatch) that also changed the state or even made the component hidden, but action execution proceeded without those changes. But I will check it more - maybe we can solve it by manipulating the execution queue or even solving this edge-case later.
  • Nested components: top level component contains a form with a field Name, and Code, and a nested component, which also contains a field called Code. When you took all the fields from your component and tried to send it, it took fields also from nested components. It's probably fixable with proper selectors.

So it seems these issue can be handled. But I still think this functionality should be triggered only with a flag via attribute, so it's an explicit behaviour, since by default fields should be synced using bind.

@kjeske
Copy link
Contributor

kjeske commented Aug 14, 2024

To solve nested components issue, it seems like we would have to clone the component DOM internally, remove all the nested components and then read the FormData.

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

No branches or pull requests

2 participants