Code Monkey home page Code Monkey logo

Comments (2)

mike-thompson-day8 avatar mike-thompson-day8 commented on August 13, 2024

The code looks about right. Although your assoc and get-in seem to work on different paths.
No idea how (or @address "") could yield a nil. Sorry but you'll have to debug.

Side issue: if you are going to be using on-change to get character by character updates (rather than on-blur) then make sure you use dispatch-sync, not dispatch (or you stand the chance of dropping chars). See day8/re-frame#39.

from re-com.

yayitswei avatar yayitswei commented on August 13, 2024

Good to know about dispatch-sync.

I put together a few helper functions for wiring up form elements. The textbox model needs a dereference but the radio button doesn't.. I'll investigate more.

(defn wired-textbox [{:keys [label key]}]
  (let [model (subscribe [::input key])]
    (fn []
      [rc/v-box
       :children
       [[rc/label :label label]
        [rc/input-text
         :model (or @model "")
         :on-change #(dispatch [::input-changed key %])]]])))

(defn wired-radiogroup [{:keys [label key options]}]
  (let [model (subscribe [::input key])]
    (fn []
      [rc/v-box
       :children
       [[rc/label :label label]
        [rc/v-box
         :gap "10px"
         :children
         [(doall (for [[c label] options]
                   ^{:key c}
                   [rc/radio-button
                    :label label
                    :value c
                    :model model
                    :label-style (if (= c @model) {:font-weight "bold"})
                    :on-change #(dispatch [::input-changed key c])]))]]]])))

[wired-textbox {:label "Address" :key :address}]
[wired-radiogroup {:label "Color"
                          :key :color
                          :options [[:blue "Blue"] [:red "Red"]]}]

Btw, re-com is the best component library I've used so far. Thanks for releasing it! Hope to see more adoption and continued updates.

from re-com.

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.