11 ms·
What was in your json? I've taken forms pretty far with htmx. Getting to accept "the state lives in the html" takes a bit of mental wrangling, but I've found it
by smallerfish 3y ago
What was in your json? I've taken forms pretty far with htmx. Getting to accept "the state lives in the html" takes a bit of mental wrangling, but I've found it to hold up well so far. (One nice htmx trick is the ability to include hidden inputs/forms/whatever from outside the current form if necessary.)
- mst 3y agofrom outside? (I swear I've read the htmx docs but either I missed this part or I've forgotten it since)
- artificialLimbs 3y agohx-include https://htmx.org/attributes/hx-include/ https://htmx.org/attributes/hx-include/
- masfoobar 3y agoHi smallerfish update: formatted the json better Thank you for expressing interest and, potentially, an approach to suggest ideas. On my original attempt, I just couldn't get the POST request to work. I cannot remember the details but, due to time constraints, had to resort to something. I will admit that this is an area I would like to revisit, but the current approach does work well... for now. My json is larger than below, but provides examples of the inputs they represent on screen:- { "catA": { "capacity": 90, // value from slider control "memberType": 4, // value from single drop down "members": [1, 2, 10, 100], // values from multi select drop down }, "catB": { "dateRange": { // both individual text fields "from": "2024-01-03 10:00:00", "to": "2024-01-04 10:00:00" } } }
- smallerfish 3y agoI've found it most useful to have form types that are derivable from db entities, but which are designed for parsing (and rendering) forms. What backend library do you use? Mine (javalin) gives me back forms as: `Map<String, List<String>>`, i.e. a map of form keys to list of values. In your case, you have five keys that matter: capacity, memberType, members, from, to - so you could have a completely flat form object from which you derive your catA and catB entities easily enough. I wrote a function which converts from the generic form structure to a more nested/typed structure, but I found that two levels of nesting becomes hard (maybe impossible) to reason about (consider lists with mismatched lengths, and how you'd handle them on nested objects); in any case, I'd be able to have: data class MyForm(val catA: CatA, val catB: CatB) ...where CatB is flattened: data class CatB(val from: OffsetDateTime, val to: OffsetDateTime) ...and then I'd be able to transform the form as: request.toFormObject<MyForm>() I've found this to hold up well so far. (I plan to write a few blog posts about the whole stack I'm playing with, including this -- subscribe on http://smaller.fish http://smaller.fish if interested in seeing them when published. No spam.)
- masfoobar 3y agoAppreciate your reply. I agree with your comment. I need to revist. Maybe I will be successful next time round. :-)