luciodale / fork

A non-intrusive Clojurescript form management library for Re-frame and Reagent.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dirty does not always return dirty

FSpoering opened this issue · comments

Hey

First of all, thanks a lot for your effort. Much appreciated. But sadly i did run into some trouble. I have built kind of a custom Fieldarray where i basically can generate a list of 0 - n entries. Every entry gets assigned an index. If i now initialize the form with lets say 2 entries in the list, and i then remove the last entry, the form shows as not dirty. I tracked it down to the following line:

(first (data/diff values (or initial-values {}))))

Thing is, since the initial-values now contain more entries than the current values, the first return value will be nil. But the second value will be showing the now removed entry.

Small example
(clojure.data/diff {0 {:a 1}} {0 {:a 1} 1 {:a 1}})

So to really detect if the form is dirty, you should also check the second list of the return value. Something along:

(seq (filter some? (butlast (clojure.data/diff values (or initial-values {}))))

Hey @FSpoering! First of all, thanks for using the lib. I definitely added thedirty logic before the field array so good spot!

Feel free to open a PR and I will proceed to merge it :)