3 ms·
1. One of the most painful thing with SSR forms is passing the data back-and-forth between the server and client when there are validation errors. Sometimes the
by Xeoncross 4y ago
1. One of the most painful thing with SSR forms is passing the data back-and-forth between the server and client when there are validation errors. Sometimes the data is very sensitive and you have to return the form with some values (like SSN) empty and make the user retype that along with with whatever field(s) were the actual issue. I'm also curious about how file uploads would work.
2. REST/GraphQL/gRPC API. Often, if you want to open up your API to internal or external users it's a lot easier if the frontend was already written to deal with protobuf or JSON endpoints. Seems like it would be painful to add an API to an htmlx backend.
Is there a good way to address these with htmlx?
- fearthetelomere 4y agoRegarding #1, I've found that Phoenix + LiveView has been helpful for these cases. They have great form validation tools using Changesets and the `phx-change` attribute [1]. You can redact certain fields [2], and even treat certain fields like virtual fields (like password not being stored vs the password hash being stored) [3]. Of course, the (potential) drawback is in using Elixir for both front-end and back-end which may be a tough sell to a client or employer. ----- [1]: https://blog.appsignal.com/2021/09/28/real-time-form-validations-with-phoenix-liveview.html https://blog.appsignal.com/2021/09/28/real-time-form-validat... [2]: https://hexdocs.pm/ecto/Ecto.Schema.html#module-redacting-fields https://hexdocs.pm/ecto/Ecto.Schema.html#module-redacting-fi... [3]: https://elixircasts.io/ecto-virtual-attributes https://elixircasts.io/ecto-virtual-attributes
- christophilus 4y agoWhy can’t you hydrate the form with the SSN? If you’re serving it via TLS, there shouldn’t be any problem. It’s no different sending it up to the client than it is for the client to send it down to you. Unless you’re logging every rendered page for some reason, I guess.
- P5fRxh5kUvp2th 4y agoIt was just an example, replace SSN with password if you'd prefer.
- recursivedoubts 4y agohttps
- harryvederci 4y ago1. I think you can just throw an error, and instead of swapping your filled-in form, you make a validation error appear below the form, e.g. 2. So far in my experience a rest API for my own front end has been pretty specific, so I'd want to add a separate API anyway for that purpose.
- roywiggins 4y agoWith something like Django you can make a quick and dirty json API by just returning the context dictionary that you were passing into the template renderer.