fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
Alex Piers 2021-02-13T02:43:38.386400Z

Normally, you put join in the query only when you want to go one level deeper into the child, because the shape of the query is supposed to match the shape of the ui. Therefore, :account/edit should be a property just like :account/id, :account/name, etc. In Tony's book, he actually gave an excellent example to show you how editing? can be done. Do check this out: https://book.fulcrologic.com/#_focusing_an_input

Alex 2021-02-13T05:34:32.386600Z

@alexpiers.fp thank you

Alex 2021-02-13T06:01:34.386800Z

So adding the :account/editing? to my data worked when I want to support multiple rows being edited at the same time. However if I only want 1 row being edited at a time what's best practice? First thing I thought of was write a mutation that toggles all :account/editing? to false and then toggling the 1 record that needs to be edited to true.

Alex 2021-02-13T06:10:15.387Z

ah nvm I think I got it 😄

Alex 2021-02-13T17:19:03.394800Z

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)})])}
                                 "Save")
                     (dom/button {:onClick
                                  #(prim/transact! this `[(app.model.account/cancel-account-edit {:account-id ~id})])}
                                 "Cancel"))))))

Jakub HolĂ˝ 2021-02-14T11:31:39.397500Z

? 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

Alex 2021-02-14T15:11:38.397700Z

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

Alex 2021-02-14T15:12:36.398100Z

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Ă˝ 2021-02-14T17:27:18.399700Z

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Ă˝ 2021-02-14T17:29:50.399900Z

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

Alex 2021-02-17T03:45:19.434500Z

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

Jakub HolĂ˝ 2021-02-13T20:56:31.395400Z

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

Jakub HolĂ˝ 2021-02-13T20:58:57.395600Z

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?

henrik 2021-02-13T22:37:33.396600Z

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

henrik 2021-02-13T22:38:24.396800Z

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