fn-fx / fn-fx

A Functional API around JavaFX / OpenJFX.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do you get the selected value from a choice-box

jdkealy opened this issue · comments

(defui Choice
  (render [this _]
          (ui/choice-box
           :on-action {:event :choose-env :this this  }
           :items ["development"
                   "staging"
                   "production"] )))

In the "choose-env" handle, I have no access to what item was chosen. I tried to pass "this" as an argument and call (.getSelectionModel this) in the event handler, but there's no such method. How are you supposed to get the chosen item ?

Answering my own question here.

 :fn-fx/include {::new-item #{:selection-model}}

is put into the component, and the event handler has access to the component that triggered the event

(.getSelectedItem  (:selection-model   (:filewatcher.handler/choose-env   includes)))
(defui MainWindow
       (render [this {:keys [todos]}]
          (ui/v-box
            :style "-fx-base: rgb(30, 30, 35);"

            :padding (ui/insets

                     :top-right-bottom-left 25)
            :children [(ui/choice-box
                        :items ["development", "staging", "production"]
                        :id ::choose-env
                        :on-action {:event :choose-env 
                                    :fn-fx/include {::choose-env #{:selection-model}}})])))


(defmethod handle-event :choose-env
  [state {:keys [fn-fx/includes]}]
  (println (.getSelectedItem  (:selection-model   (:filewatcher.handler/choose-env   includes))))