Fork me on GitHub
#re-frame
<
2017-12-18
>
genRaiy17:12:30

odd little question

genRaiy17:12:15

on line 10 … I need to fully disambiguate gap …. but only here

p-himik17:12:01

@raymcdermott You have gap argument.

genRaiy17:12:07

I see an error like this in the console

genRaiy17:12:12

template.cljs?rel=1513207500959:302 Uncaught Error: Assert failed: Invalid Hiccup form: [nil :size "1"]

p-himik17:12:34

Look at the second line of your example.

p-himik17:12:21

I think it's better to use aliases for namespaces like (require '[re-com.core :as rc]) and then use rc/gap, rc/label etc to avoid errors like this.

genRaiy17:12:40

ok, so if I use gap in the h-box I’m not allowed to use [gap …]

genRaiy17:12:46

rc/xxx is a bit uglier but if it works more reliably - fair enough

danielcompton19:12:36

@raymcdermott just to confirm this is a name shadowing issue, not specific to re-com

Jarrod Taylor (Clojure team)22:12:12

Assuming the ::form-errors? subscription is updated by the ::validate-form dispatch. What is the best way to ensure it is done running before checking the errors and dispatching the ::submit-form?

(defn submit-button []
  [:button#submit-button {:type "submit"
                          :on-click (fn [e]
                                      (rf/dispatch [::validate-form])
                                      (when (not @(rf/subscribe [::form-errors?]))
                                        (rf/dispatch [::submit-form])))}
   "Submit"])

mikerod23:12:15

@jarrodctaylor you can use the :dispatch effect that is provided with re-frame from a single form submission event handler

mikerod23:12:45

(rf/reg-event-fx
 ::validated-submission
 (fn [{:keys [db]} event-vec]
   (let [errors (do-validation <whatever needed>)]
     (if (empty? errors)
       {:dispatch [::submit-form]}
       {:db (assoc db ::form-errors errors)}))))

mikerod23:12:31

and your :on-click is just :on-click (fn [e] (rf/dispatch [::validated-submission]))