As of right now all the selectors are done at compile time so dynamic
selectors are not possible. That being said I think there are several ways
to accomplish what you are trying to do. Is there a reason you are
calling om/build here instead of just calling do-input-field. I am trying
to understand what the sub component is used for. Below is another
approach that is a bit more declarative.
(defn custom-transform [text]
(fn [node]
(-> node
(assoc-in [:attrs :value] text)
(assoc-in [:attrs :onClick] handler1))))
(defn form-app [data owner]
(reify
om/IRender
(render [_]
(kioo/component
"public/fragments/f1.html" [:#header]
{[:input#name] (custom-transform (get data :input#name))}))))
On Mon, May 19, 2014 at 4:34 PM, Mark Fisher <[email protected]>wrote:
> Is it possible to have dynamic selectors in kioo?
>
> The app i'm writing is a simple form with many input fields, and wanted to
> generalise each input component by passing in the tag to match against, e.g.
>
> (defn editable [data owner {:keys [edit-key input-field] :as opts}]
> (reify
> om/IInitState
> (init-state [_]
> {:editing false})
>
> om/IRenderState
> (render-state [_ {:keys [editing]}]
> (let [text (get data edit-key)
> minput (keyword (str "input#" (name edit-key)))]
> (kioo/component
> "public/fragments/f1.html" [input-field]
> {[input-field] (do-input-field text edit-key data owner)})))))
>
> ;; do-input-field sets the :value attr and various listen handlers on the
> input field
>
> (defn form-app [data owner]
> (reify
> om/IRender
> (render [_]
> (kioo/component
> "public/fragments/f1.html" [:#header]
> {[:input#name]
> (substitute
> (om/build editable data {:opts {:edit-key :name :input-field
> :input#name}}))}))))
>
> the app data being:
> {:name "initial name" :address "initial address"} etc
>
> and my form is simply:
> <header>
> <input id="name"/>
> <input id="address"/>
> ... etc
> </header
>
> but this doesn't seem to work. Is this possible?
>
> I'm ultimately trying to build the form using the keys from the app-data
> and matching them to form inputs directly, even in the form-app function,
> but getting just 1 field to work would be a good start.
>
> --
> 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.
>
--
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.