Parsing and Assigning the Sorting Parameters

Our LiveView receives the sorting parameters in the handle_params/3 callback when the website is mounted or when the user changes the parameters through our SortingComponent.

As with all user input, we want to make sure that the received parameters are indeed valid. We don’t want to build the validation ourselves though. Luckily Ecto.Changeset offers the functionality of parsing and validating the parameters for us. We’ll use this functionality inside a schemaless changeset called SortingForm. Before we can create this form though, we have to take a small detour into the differences between a schema changeset and a schemaless changeset.

Using Ecto.Enum Inside a Schemaless Changeset

If you want ...

Get Building Table Views with Phoenix LiveView now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.