luciodale / fork

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to resubmit the form after server-side errors?

danieldroit opened this issue · comments

upon return of the server-side failure response I use the fork/set-error to set the errors.
This prevents the form from being resubmitted as frok.core/handle-submit requires server errors to be empty.

The idea is that if there are errors the form should not be submitted. You can take advantage of the clean-on-refetch key that makes sure to clear any old state before sending a new request.

:on-change (fn [evt]
                      (handle-change evt)
                      (send-server-request
                       {:name "foo"
		       ;; to clean up relevant state before each http request
		       :clean-on-refetch ["foo"]}
                       #(rf/dispatch [:server-request %])))

If you don't want to rely on this helper, you can dissoc the specific key i.e. foo from the :server map stored in your state. You should do this before you send the request to the server in your :server-request handler, if we look at the above example.