Fork me on GitHub
#fulcro
<
2023-05-24
>
Jakub Holý (HolyJak)07:05:01

@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)

2
Jakub Holý (HolyJak)07:05:10

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? 🙏

Jakub Holý (HolyJak)13:05:16

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)

tony.kay13:05:37

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.

tony.kay14:05:43

But you are right that the “naive” check from form.cljc should be updated to handle references better

tony.kay14:05:55

Try 1.4.9-SNAPSHOT

tony.kay14:05:10

I improved the default check

Jakub Holý (HolyJak)14:05:46

Awesome, thx a lot! Will try it ASAP.

tony.kay14:05:38

Technically, the default validator should probably validate edges 😕

tony.kay14:05:46

so that ao/valid? works as well

tony.kay14:05:11

on to-one edges it isn’t necessary, but on to-many you might want to enforce a count

tony.kay14:05:59

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.

tony.kay14:05:38

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?

Jakub Holý (HolyJak)14:05:59

It's hard. Personally I prefer to disable incorrect uses, even if it can break something.

tony.kay14:05:05

the fix i just did may not be right….but i know what to do

👍 2
tony.kay14:05:23

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

tony.kay14:05:37

let me know if that seems to break anything. If not, I’ll do a release

👍 2
Jakub Holý (HolyJak)07:05:52

It works perfectly, thank you!

tony.kay21:05:54

cool, yeah, I tried it out in demo and it does seem ok