Yes, it’s easy with JS, but I’m using LV because I don’t want to use JS. I have a schema with something like: Parent, Child, where Parent hasmany Children // Child belongsto parent. Im experimenting with Phoenix 1.6 and LiveView, and trying to get my nested form/models to work as expected. I just wish LiveView or maybe Ecto had better support for doing this, since it seems having buttons to clear form inputs is a common UI paradigm. Phoenix LiveView Nested Associations Form. : Replaced usage of /3 in 'add-line' and 'delete-line' event handlers with custom function using /3 with a fallback of /3. The “clear-time” handler always has a full params map to work with and can clear out whatever fields it needs to, then creates a fresh changeset from the params to send to the template and form_for. : Updated to work with phoenix 1.7.0 form changes. On validate, LiveView is sending me the params from the form, so I can just use that and store it back in the assigns. From what I understand that’s one of the use cases for using LiveView, so here’s my problem: The. Currently I am trying to enhanve a simple CRUD form with LiveView to get live validation, but so that this is optional and the site will still work if JavaScript has been disabled. ![]() LiveView, Phoenix.View has been replaced by Phoenix.Component. One thing that has always been problematic is when providing live form validation for a user that interacts with a form. On mount, I have to make the params myself from my record. Hello everyone I’ve recently started digging into phoenix LiveView, and so far I really like what I am seeing. Maybe something tying the form helpers and changeset together. The trick is storing the params in the assigns. Params = put_in(params, nil)Ĭhangeset = (record, params) Here’s my event handler: def handle_event("clear-time", args, socket) do Finally, item2 and item3 attributes are cast and validated. LiveView The validate callback simply updates the changeset based on all form input values, then convert the changeset to a form and assign it to the socket. Next, item2 and item3 attributes are changed if needed (i.e. From the docs (specifically the 'With connection data' section): formfor/4 expects as first argument any data structure that implements the protocol. When handling phx-change event, firstly the item1 attribute is cast and validated. 1 Answer Sorted by: 35 You can use formfor/4 passing a Plug.Conn as the first argument. ![]() I’m not sure what you mean, but what I’m doing seems so cumbersome for something seemingly so simple, that I feel like I’m missing something. I solved the problem with two phase changeset casting.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |