reagent-project / reagent-forms

Bootstrap form components for Reagent
339 stars 78 forks source link

Select with options from the app db #124

Closed alaibe closed 6 years ago

alaibe commented 6 years ago

Hey, Here is what I am trying to do:

(defn configure []
      (let [currencies (re-frame/subscribe [::subs/currencies])
            timezones (re-frame/subscribe [::subs/timezones])
            current-timezone (re-frame/subscribe [::subs/current-timezone])
            current-currency (re-frame/subscribe [::subs/current-currency])
            doc (atom {:currencies @currencies
                       :timezones @timezones
                       :currenry @current-currency
                       :timezone @current-timezone})]
           (fn []
               [:div.modal-content
                [:div.modal-header
                 [:h5.modal-title (str "Configure")]
                 [:button.close {:type "button" :data-dismiss "modal" :aria-label "Close"}
                  [:span.fa.fa-close {:aria-hidden "true"}]]]
                [:div.modal-body
                 [bind-fields configure-form doc]]
                [:div.modal-footer
                 [:button.btn.btn-primary
                  {:type "button"
                   :on-click #(re-frame/dispatch [:client.layout.events/configure @doc])}
                  (str "Save changes")]
                 [:button.btn.btn-secondary {:type "button" :data-dismiss "modal"} (str "Close")]]])))
(def configure-form
      [:form
       [:div.form-group
        [:label "Select a currency"]
        (into [:select.form-control {:field :list :id :currency}] (map options currencies))]
       [:div.form-group
        [:label "Select a timezone"]
        (into [:select.form-control {:field :list :id :timezone}] (map options timezones))]])

How can I use data that comes from outside in my form in order to display them as options?

Thanks

yogthos commented 6 years ago

This looks related to the issue with updating state externally https://github.com/reagent-project/reagent-forms/issues/107 unfortunately that's not currently supported. You might want to take a look at re-com for working with re-frame instead.