Fork me on GitHub
#fulcro
<
2022-10-22
>
roklenarcic12:10:55

The relevant docs are here https://book.fulcrologic.com/RAD.html#_to_one_relation_to_pre_existing But this picker example doesn’t include what to do when picking nothing is a valid value or when the list of preexisting is empty. The whole thing seems to malfunction and start referencing ident [:ident nil] .

roklenarcic18:10:17

Solved it by setting inital state of parent to nil

tony.kay09:10:43

I think the picker can also be told it is clearable. That said, the whole system is easily pluggable, so you can augment the state machine, change the implementation of the control, etc. It is possible you uncovered a bug with a workaround, since the built in picker should not set the value to a bad ident. I may have released an initial state improvement recently that broke that for that case

roklenarcic09:10:13

I think the cause is that when form/create! is called, a full initial state tree is initialized, including subform, and the system considers a to-one ref to parent a subform automatically, so it initializes it with nil data, which normalizes to [category/id nil]. By setting initial state option to nil by: `

(form/create! app-ish CategoryForm {:initial-state {::m.category/parent nil}})
I;ve managed to force it to initialize without a parent link

roklenarcic09:10:46

The parent picker is empty list when no categories have been created yet

roklenarcic09:10:41

The picker problem I addressed with:

(cons {:text "None" :value nil}
      (map (fn [{::m.category/keys [id title]}]
           {:text title :value [::m.category/id id]})
      categories))

roklenarcic09:10:26

so I’ve added an explicit none value at the top

roklenarcic19:10:17

Ok my workaround prompts a bunch of errors.

Subforms for class roklenarcic.ui.category/CategoryForm must include a ::form/ui entry for Object

 Subform class null must include a ::form/id that is an attr/attribute

Subform not declared (or is missing ::form/id) for Object on roklenarcic.ui.category/CategoryForm

tony.kay22:10:42

Are you using the latest version? If so, try backing off a few steps and see if that works. I did an initial ui props fix recently that could be causing the problem. I’m not sure it should, but it might

tony.kay22:10:03

you could also try this fix, GIT commit SHA 6eeb448896b5f15e7aaa87aa19f05ff747b74e0d in deps for fulcro-rad

tony.kay22:10:18

If that fixes it, then I’ll push a new version

roklenarcic18:10:42

Is it possible to tell form to add the item to some list in the state after a new item is successfully saved?

tony.kay08:10:43

You have save middleware if you need to augment the same as it happens on the server, and triggers on the form itself if it is a UI concern.

roklenarcic08:10:29

interesting… I haven’t really noticed client-side form middleware

roklenarcic14:10:09

Mainly I lack an easy strategy of updating pickers and lists of entities when adding entities.

tony.kay04:10:45

So there is not client side middleware, just the state machine. However, the server side middleware can modify things and because the complete form state is returned from the save mutation, it can have the visible effect of changing what's on screen after the save.