hydrostack / hydro

Hydro brings stateful and reactive components to ASP.NET Core without writing JavaScript
https://usehydro.dev
MIT License
692 stars 16 forks source link

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

Open taublast opened 1 month ago

taublast commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

There were some edge-cases, like:

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 commented 1 month ago

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.