Fork me on GitHub
#fulcro
<
2023-03-30
>
Grimgog11:03:25

How to change a defattr defined variable in an edit form in the fo/trigger :on-change ? I tried 2 different approaches - both are being triggered but the variable for "inactive-date" is not being set. a) apply-action:

fo/triggers {:on-change (fn [{::uism/keys [state-map] :as uism-env} form-ident key old-value new-value]
                                            (case key
                                              :member/active?
                                              (let [target-path (conj form-ident :member/inactive-date)]
                                                (when (not new-value) (uism/apply-action uism-env assoc-in target-path (datetime/now)))))
                                            ;; default
                                            uism-env)}
b) set-value:
fo/triggers {:on-change (fn [{::uism/keys [state-map] :as uism-env} form-ident key old-value new-value]
                                            (case key
                                              :member/active?
                                              (when (not new-value) (uism/set-value! this state-map :member/inactive-date (datetime/now))))
                                            ;; default
                                            uism-env)}
The idea is that if the attribute "active?" is being set to false then my inactive-date should be set to datetime/now. btw:
[com.fulcrologic.rad.type-support.date-time :as datetime]
Any advice is being appreciated! 😄

Eric Dvorsak15:03:08

2 things: • I don't think you have access to "this" in the trigger so you can't use it, but you have uism-env • what happens when new-value is true? I think you will have issues if you don't return the uism-env in the trigger

Eric Dvorsak15:03:22

is :member/inactive-date in your form attributes? or in the query inclusions?

Grimgog05:03:30

• oh ok, so I just use uism-env for that, ok • alright, so in case of true, just return uism-env. check • :member/inactive-date is an attribute defined as defattr in my model of member