This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-24
Channels
- # aleph (1)
- # beginners (43)
- # calva (22)
- # cider (51)
- # clerk (1)
- # clj-kondo (20)
- # clojure (29)
- # clojure-denmark (1)
- # clojure-europe (73)
- # clojure-finland (28)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-spec (7)
- # clojure-uk (4)
- # clojurescript (12)
- # data-science (2)
- # datomic (51)
- # events (1)
- # fulcro (20)
- # hyperfiddle (28)
- # integrant (6)
- # malli (20)
- # matrix (2)
- # music (1)
- # off-topic (66)
- # reitit (17)
- # releases (5)
- # ring (1)
- # shadow-cljs (31)
- # xtdb (6)
@tony.kay In the form/valid?
https://github.com/fulcrologic/fulcro-rad/blob/2944f3ae94225c48562d2de2a65637d45655d4f4/src/main/com/fulcrologic/rad/form.cljc#L1621, it checks (not (nil? ...))
but in my case I have a to-many ref attribute, which is currently “empty” but it is not nil but []
so it seems valid, even though it should not. Is the logic here insufficient for the case of to-many refs? Or is ao/required?
on to-many ref attributes not expected to work? Am I supposed to add a custom ? (I have just started to create a new item, I am not sure why the to-many shows as [] and not nil in the data)
I am not sure what is happening.. In Console I can see
> Form is not valid because required attribute is missing: :order/order-lines
> Form ...order-forms/OrderForm valid? false
> …
> :order/order-lines is not marked complete
yet when I click save, the form is saved (save-form goes over the wire, with :order/order-lines {:before nil, :after []}
). So
1. Contrary to what I wrote initially, RAD seems to detect correctly that the required to-many is missing and marks it invalid
2. Somehow, despite being invalid, save is not stopped
What am I missing? 🙏
Actually I see in console valid? true now: > Activating state :State/saving > … valid? true > … dirty? true > :order/order-lines is not marked complete > :order/order-lines is not marked complete > … valid? true > … dirty? true > :order/order-lines is not marked complete > :order/order-lines is not marked complete > Trigger … :event/save-failed (Not sure why all lines are logged twice. The save fail thx to my backend check)
edge validation is tricky. By default form-state validators do not even check them (you have to ask it to). The generated form will have a validator based just on the attributes listed, but will not validated edges. You have to make your own validator and turn on edge validation to get what you want.
But you are right that the “naive” check from form.cljc should be updated to handle references better
Awesome, thx a lot! Will try it ASAP.
on to-one edges it isn’t necessary, but on to-many you might want to enforce a count
Problem is that’s a breaking change. Really both are, but only if you are relying on the bug. Always torn on how to fix these.
it isn’t a breaking change if you were using it “right”, but if you were relying on the bug it is…so I guess by the true definition it is not actually a breaking change even though it could break your application?
It's hard. Personally I prefer to disable incorrect uses, even if it can break something.
OK, I just pushed a new snapshot that has the following changes:
• Refs are enabled by default on the validator generated for a form (if you don’t set one)
• The required setting should work for refs now (with default settings)
• The ao/valid?
should also now be invoked for refs to allow checking things like the correct number of items in a to-many
Will do
It works perfectly, thank you!