bilus / reforms

Beautiful Bootstrap 3 forms for Om, Reagent and Rum.
Eclipse Public License 1.0
168 stars 7 forks source link

Error when binding array: gen-dom-id does not allow numeric indices in korks #4

Closed undernorthernsky closed 9 years ago

undernorthernsky commented 9 years ago

For example (using reagent-reforms 0.3)

(defn http-header-entry [cursor]
  [:div.row
   [:div.col-md-4 (f/text "Header name" "" cursor [:name])]
   [:div.col-md-2 (f/select "type" cursor [:type] (map #(vector % %) ["string" "file"]))]])

[f/panel "Http headers"
        (doall (for [idx (range (count (:headers @data)))]
                 (let [c (cursor data [:headers idx])]
                   (http-header-entry c))))])

Fails with

Uncaught Error: Doesn't support name: 0
cljs$core$name @ core.cljs:8279
(anonymous function) @ core.cljs:4199
cljs.core.map.cljs$core$IFn$_invoke$arity$2 @ core.cljs:4199
cljs.core.LazySeq.sval @ core.cljs:2995
cljs.core.LazySeq.cljs$core$ISeqable$_seq$arity$1 @ core.cljs:3037
cljs$core$seq @ core.cljs:1060
cljs.core.Cons.cljs$core$INext$_next$arity$1 @ core.cljs:2865
cljs$core$next @ core.cljs:1105
clojure.string.join.cljs$core$IFn$_invoke$arity$2 @ string.cljs?rel=1441920015846:79
clojure$string$join @ string.cljs?rel=1441920015846:66
reforms.core.impl.gen_dom_id.cljs$core$IFn$_invoke$arity$1 @ impl.cljs?rel=1441920017026:92
reforms$core$impl$gen_dom_id @ impl.cljs?rel=1441920017026:90
reforms.core.impl.gen_dom_id.cljs$core$IFn$_invoke$arity$2 @ impl.cljs?rel=1441920017026:94
reforms$core$impl$gen_dom_id @ impl.cljs?rel=1441920017026:90
reforms.core.impl.html5_input_STAR_.cljs$core$IFn$_invoke$arity$variadic @ impl.cljs?rel=1441920017026:191
reforms$core$impl$html5_input_STAR_ @ impl.cljs?rel=1441920017026:189
cljs$core$apply_to @ core.cljs:3421cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic @ core.cljs:3467
cljs$core$apply @ core.cljs:3424
reforms.core.html5_input.cljs$core$IFn$_invoke$arity$variadic @ core.cljs?rel=1441920016647:140
reforms.core.html5_input.cljs$lang$applyTo @ core.cljs?rel=1441920016647:123
cljs.core.apply.cljs$core$IFn$_invoke$arity$3 @ core.cljs:3441cljs$core$apply @ core.cljs:3424
reforms.core.text.cljs$core$IFn$_invoke$arity$variadic @ core.cljs?rel=1441920016647:151
reforms$core$text @ core.cljs?rel=1441920016647:142
comm_spec$core$http_header_entry

Changing the arity-1 version of reforms.core.impl/gen-doc-id to stringify numbers seems to work for me.

+(defn- as-name-part [v] (if (number? v) (str v) (name v)))
+
 (defn gen-dom-id
   ([path]
-   (str/join "-" (map name path)))
+   (str/join "-" (map as-name-part path)))

Applied against ab8648a, haven't tried master (yet).

bilus commented 9 years ago

Thanks for bringing this out and for a detailed diagnosis. I've made a similar although a bit more general change. The fix will be a part of 0.4.0 (where it will be more extensively tested:) but I just pushed out 0.3.1-SNAPSHOT especially for you.

undernorthernsky commented 9 years ago

Thanks; decided to switch to 0.4