I've followed through the Om tutorial 
(https://github.com/swannodette/om/wiki/Basic-Tutorial) and found it quite 
helpful. However, after trying to add validation to the classes example it 
seems my understanding isn't quite right.

----

In the contacts example there is an input field with its value pulled from 
local component state. And then an onChange handler:

(defn handle-change [e owner {:keys [text]}]
  (let [value (.. e -target -value)]
    (if-not (re-find #"[0-9]" value)
      (om/set-state! owner :text value)
      (om/set-state! owner :text text))))

This prevents typed numbers from showing up in the input field.

----

In the people/classes example there are editable fields pulling their value 
from application state. I tried making the onChange handler look like this:

(defn handle-change [e text owner]
  (let [new-text (.. e -target -value)]
    (om/transact! text (fn [old-text]
                         (if-not (re-find #"[0-9]" new-text)
                           new-text
                           old-text)))))
                           
This has the desired effect of not changing the application state to ever 
include numbers, but it still shows any numbers I type in the input field... 
which should be getting it's value from application state? I'm rather new to 
both Om and React, so any help understanding the render flow and how these 
examples are different would be greatly appreciated.

(source files: https://gist.github.com/geoffrys/9042249)

-- 
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.

Reply via email to