Git Product home page Git Product logo

Comments (3)

olivergeorge avatar olivergeorge commented on May 27, 2024

Quick follow up, this approach got me a bit closer. I use (vec (concat ...)) to package up the options.

(defn Option [props owner]
  (om/component
    (let [[value display] props]
      (dom/option #js {:value value} display))))

(defn Select [props owner]
  (om/component
    (let [{:keys [label value on-change help placeholder disabled
                  options default-option default-value]} props
          default-value (or default-value "")
          default-option (or default-option "Please select")]
      (html [:div.form-group
             (if label [:label label])
             (vec (concat
                     [:select.form-control {:value       (or value default-value)
                                            :placeholder placeholder
                                            :disabled    disabled
                                            :on-change   on-change}
                     (if options
                        (dom/option #js {:value default-value :disabled true} default-option))]
                     (om/build-all Option options)))
             (if help [:p.help-block help])]))))

Note: I still have to use (dom/option...) to avoid two of the errors:

from sablono.

the-kenny avatar the-kenny commented on May 27, 2024

Oliver George [email protected] writes:

Quick follow up, this approach got me a bit closer. I use (vec (concat ...)) to package up the options.

(defn Option [props owner]
  (om/component
    (let [[value display] props]
      (dom/option #js {:value value} display))))

(defn Select [props owner]
  (om/component
    (let [{:keys [label value on-change help placeholder disabled
                  options default-option default-value]} props
          default-value (or default-value "")
          default-option (or default-option "Please select")]
      (html [:div.form-group
             (if label [:label label])
             (vec (concat
                     [:select.form-control {:value       (or value default-value)
                                            :placeholder placeholder
                                            :disabled    disabled
                                            :on-change   on-change}
                     (if options
                        (dom/option #js {:value default-value :disabled true} default-option))]
                     (om/build-all Option options)))
             (if help [:p.help-block help])]))))

Note: I still have to use (dom/option...) to avoid two of the errors:


Reply to this email directly or view it on GitHub:
#48 (comment)

Those are caused by implementation details of Sablono/Om. They will
likely disappear in future releases of those.

Your 'fixed' error messages is caused by the 'list' of members in the
div.form-group: React needs key-attributes so it doesn't have to redraw
the whole list in case the order changes. With `om/build', this is done
with :key or :react-key. Inside components, Om seems to support (or
leak?) :key with a value.

While this is a bit unintuitive given the naming of options to
`om/build', it can be used to work around your warning: Just give every
child-node of div.form-group an unique key like:

[:label {:key "label"}]
[:select.form-control {:key "my-select"}]

etc.

I'm not sure if this is intended in Om: I suspect it would be
better to factor out those elements as their own components and call
`om/build' on them.

from sablono.

olivergeorge avatar olivergeorge commented on May 27, 2024

Thanks, I'll give that a go.

Might be worth having a wiki page noting common causes/resolutions
associated with react warnings.

On 22 January 2015 at 20:19, Moritz Ulrich [email protected] wrote:

Oliver George [email protected] writes:

Quick follow up, this approach got me a bit closer. I use (vec (concat
...)) to package up the options.

(defn Option [props owner]
(om/component
(let [[value display] props]
(dom/option #js {:value value} display))))

(defn Select [props owner]
(om/component
(let [{:keys [label value on-change help placeholder disabled
options default-option default-value]} props
default-value (or default-value "")
default-option (or default-option "Please select")]
(html [:div.form-group
(if label [:label label])
(vec (concat
[:select.form-control {:value (or value default-value)
:placeholder placeholder
:disabled disabled
:on-change on-change}
(if options
(dom/option #js {:value default-value :disabled true} default-option))]
(om/build-all Option options)))
(if help [:p.help-block help])]))))

Note: I still have to use (dom/option...) to avoid two of the errors:


Reply to this email directly or view it on GitHub:
#48 (comment)

Those are caused by implementation details of Sablono/Om. They will
likely disappear in future releases of those.

Your 'fixed' error messages is caused by the 'list' of members in the
div.form-group: React needs key-attributes so it doesn't have to redraw
the whole list in case the order changes. With `om/build', this is done
with :key or :react-key. Inside components, Om seems to support (or
leak?) :key with a value.

While this is a bit unintuitive given the naming of options to
`om/build', it can be used to work around your warning: Just give every
child-node of div.form-group an unique key like:

[:label {:key "label"}]
[:select.form-control {:key "my-select"}]

etc.

I'm not sure if this is intended in Om: I suspect it would be
better to factor out those elements as their own components and call
`om/build' on them.


Reply to this email directly or view it on GitHub
#48 (comment).

from sablono.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.