Chapter 5
This chapter was a little lighter than the previous, but still had some very good content.
- Building a form for data that is not persisted.
Before, when I have created changesets for data that is not saved, I have used Ecto embedded schemas. It works fine, but I like this approach also since there is nouse
statement required. - File uploads. Once again, LiveView shows that it can make complex things, such as file uploads, easy. With just a few function calls you get, not only the upload functionality, but also drag and drop, validation, progress bar and preview?? Amazing!
And throughout all this we, the developers, get to keep our mind in the server without having to context switch our brains between the frontend and backend.
Outdated form syntax
I mentioned it in my previous post, but the syntax used to build the form is slightly outdated.
We no longer need to do :let={f}
when declaring the form, and instead of <.input field={{f, :first_name}} ... />
we can do <.input field={@form[:first_name]} ...
. This is nice since the :let={f}
stuff was pretty confusing imo.
Also, the assignment to the socket is slightly different, using the to_form
function: assign(socket, :form, to_form(changeset))
.
Once again, Iām sure this will be fixed for the final release.
Iām excited to start the next chapter about Function Components