Skip to content

Instantly share code, notes, and snippets.

@ProTip
Created July 27, 2014 13:13
Show Gist options
  • Save ProTip/af0927483200b9bcacd1 to your computer and use it in GitHub Desktop.
Save ProTip/af0927483200b9bcacd1 to your computer and use it in GitHub Desktop.
(defn enable-edit [owner]
(let [input (om/get-node owner "input-box")]
(set! (-> input .-style .-display) "")
(.focus input)
(set! (.-value input) (.-value input))
(om/set-state! owner :editing true)))
(defn editable [text owner]
(reify
om/IInitState
(init-state [_]
{:editing false})
om/IRenderState
(render-state [_ {:keys [editing]}]
(dom/li nil
(dom/span #js {:style (display (not editing))
:onClick #(enable-edit owner)}
(om/value text))
(dom/input
#js {
:style (display editing)
:ref "input-box"
:value (om/value text)
:onChange #(handle-change % text owner)
:onKeyPress #(when (== (.-keyCode %) 13)
(commit-change text owner))
:onBlur (fn [e] (commit-change text owner))})))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment