Fork me on GitHub

Am I doing something wrong? I'm unable to get fs/dirty? to print true when I make changes to the form. Or when I try to get fs/dirty-fields I get an empty map as if nothing changed.

(defsc AccountItemForm
  "User Account Edit Form"
  [this {:account/keys [id name email active? editing?] :as props}]
  {:query [:account/editing? :account/id :account/name :account/email :account/active? fs/form-config-join]
   :ident :account/id
   :form-fields #{:account/name :account/email :account/active?}}
  (let [form-dirty? (fs/dirty? (prim/props this))]
    (println "Form DIrty?" form-dirty? (fs/dirty? props))
    (dom/tr :.ui.form {:classes [(when form-dirty? "warning")]}
            (dom/td (dom/input {:value name
                                :name :account/name
                                :onChange #(m/set-string! this :account/name :event %)}))
            (dom/td (dom/input {:value email
                                :name :account/email
                                :type "email"
                                :onChange #(m/set-string! this :account/email :event %)}))
            (dom/td (dom/input {:checked active? :name :account/active? :type "checkbox"}))
            (dom/td (dom/div
                     (dom/button {:onClick
                                  #(prim/transact! this `[(app.model.account/submit-account-changes {:account-id ~id :delta ~(fs/dirty-fields props true)})])}
                     (dom/button {:onClick
                                  #(prim/transact! this `[(app.model.account/cancel-account-edit {:account-id ~id})])}

Jakub Holý (HolyJak)20:02:31

I think you must first mark the changed fields as "done". Or perhaps this only applies to validation checks?

Jakub Holý (HolyJak)20:02:57

Remember UI = f(data) so look at what data and form data is in the DB. Also, is the initial form state added correctly when adding account data to the DB?


If you use this component to load data, try adding

{:pre-merge (fn [{:keys [data-tree current-normalized]}]
              (merge current-normalized (fs/add-form-config AccountItemForm data-tree)))}


Other than potentially that, I can't see anything that sticks out.


Thanks for the suggestions guys, I'll keep on digging.


@U0522TWDA Yes the db contains the pristine data of what account I'm trying to edit. Initially they both start as the same state. When I start editing the record in my db, not the form one, changes to w/e I'm typing.

Jakub Holý (HolyJak)11:02:39

? Huh? Have you 2 different things you are trying to edit? I'm more interested in the form state data than the entity's own data because that is used in fs/dirty


Okay I think I explained it badly, here's a screenshot of my entity and the entry that's made in forms-by-ident.


I made edits and they show up on the entity while the form pristine state remains the same. I looked at the fulcro demo for the phone numbers and that one also happens to do that.

Jakub Holý (HolyJak)17:02:18

I see. Perhaps look at how the dirty function works to see what data it looks at and why it might not be doing what you expect? Perhaps also try to call it from the REPL instead of just on render in the body?

Jakub Holý (HolyJak)17:02:50

Does transacting (fs/mark-complete! ...) has any effect on the output of dirty?


@U0522TWDA thank you for the suggestions and sorry for the late reply. I'll be trying this out on the coming days.