rum

Simple, decomplected, isomorphic HTML UI library for Clojure and ClojureScript | 0.12.8 https://github.com/tonsky/rum/blob/gh-pages/CHANGELOG.md#0128
martinklepsch 2017-07-17T06:32:05.145146Z

@jrychter can you share? 🙂

jrychter 2017-07-17T08:37:10.137372Z

@martinklepsch I'm considering it in the future — though it will be a lot of work to document it and polish the edges. For now I think I'll keep using it for a while, as I find that each new edge case makes it slightly better.

jrychter 2017-07-17T08:41:11.217276Z

It's a very different approach from what you have, though. Here's an example, a simple but realistic use:

(rum/defc edit-price-break < rum/static [{:keys [:quantity :price] :as data} submit-fn]
  (forms/form data
              (merge (xforms/pos-int :quantity)
                     (xforms/pos-number :price))
              [[:quantity fields/text]
               [:price fields/text]]
              {}
              submit-fn
              :layout-fn (fn [{:keys [quantity price]}]
                           [:div.two.fields
                            [:div.field quantity]
                            [:div.field price]])
              :buttons-fn (fn [correct? ok-fn cancel-fn]
                            [:div.ui.right.floated.tiny.primary.button {:class (when-not correct? "disabled")
                                                                        :on-click ok-fn}
                             [:i.arrow.up.icon] "Add"])))

jrychter 2017-07-17T08:43:22.261164Z

The :layout-fn and :buttons-fn are optional — you get a sequential layout and a default OK button if you don't provide them. The form does instant validation (highlighting the error fields, and disabling buttons) according to validators defined in xforms (second argument to form). Example of an xform:

(defn integer [k]
  {k {:display (comp tools/or-empty k)
      :edit #(str (or (get % k) ""))
      :parse (comp tools/to-int k)
      :validate (comp integer? k)}})

jrychter 2017-07-17T08:43:46.269293Z

A pos-int adds another validator:

(defn pos-int [k]
  (-> (integer k)
      (add-validator k (fn [{n k}] (> n 0)))))

jrychter 2017-07-17T08:44:15.279350Z

All this provides declarative forms (and tables, too), with lots of code reuse, and yet is flexible enough to do even dynamic forms which change depending on what is selected in one of the fields.