Hi all,
I'm trying to understand om and build a simple input field with validation,
hacked together from the tutorial.
For some data like this
{:key "name"
:value "Ben"
:hint "max. 30 Zeichen"
:validate "max-30"}
and a component like this:
(defmulti handle-change (fn [e state owner] (:validate state)))
(defmethod handle-change "max-30" [e state owner]
(handle-change-max-30 e state owner))
(defmethod handle-change :default [e state owner]
(om/set-state! owner :hint "Que?"))
(defn input-view [entry owner]
(reify
om/IInitState
(init-state [this]
{:text (:value entry)
:hint (:hint entry)
:validate (:validate entry)})
om/IRenderState
(render-state [this state]
(dom/div nil
(dom/input
#js {:type "text"
:value (:text state)
:onChange #(handle-change % state owner)
(dom/span nil (str " " (:hint state)))))))
I get
"Uncaught Error: Cannot manipulate cursor outside of render phase, only
om.core/transact!, om.core/update!, and cljs.core/deref operations allowed".
when I start to edit the field.
So I thought I needed to deref the entry in init-state, but sadly om says
that's not allowed in the render phase. (at least I now know that init is part
of the render phase...)
So, it seems I'm not understanding something here... I'm new to clojure and
om/react. Can someone give me some way to better understand what's going on? Is
my sketch a useful way of thinking about this in om, or do I need to look at
this from a different angle?
Thanks for any help, pointers new ways of doing this,
Mathias
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.