This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-25
Channels
- # beginners (32)
- # boot (1)
- # cljs-dev (25)
- # cljsrn (1)
- # clojure (35)
- # clojure-dev (6)
- # clojure-nl (4)
- # clojure-russia (12)
- # clojure-spec (13)
- # clojure-switzerland (2)
- # clojurescript (63)
- # cursive (9)
- # datomic (18)
- # dirac (32)
- # graphql (6)
- # luminus (8)
- # off-topic (18)
- # pedestal (5)
- # protorepl (1)
- # re-frame (30)
- # remote-jobs (5)
- # untangled (61)
- # yada (7)
I have a form with a form-spec
that includes a f/dropdown-input
. I'm looking for the event that 'the user has selected a different value' - I need to transact!
a mutation when this happens. It is not clear to me how to go about hooking into the event.
@cjmurphy I don’t think, at the moment, it generates events. The form support is young. There is the on-form-change support.
You could easily augment the ::dropdown form-field rendering and add support for a callback
was thinking might have to do something like that but looked a bit tricky so thought I'd ask first.
not that tricky…there isn’t much to the forms support internally. It just makes a copy of the original field values. The field rendering just hooks up the change events.
So i'll actually have to make a change to the library, or it should be able to handle it?
I think that is a valid use-case: wanting to add you own additional event handling to change events
‘[(do-thing {:value ???})]` is valid data, and we could technically invent a placeholder for the current value
I can see in the transaction log: [:user-request/by-id USER-REQUEST-FORM] transacted '[(untangled.ui.forms/select-option {:form-id [:user-request/by-id USER-REQUEST-FORM], :field :request/period, :value ":q2"}) {:root/user-request [:untangled.ui.forms/form-root]}], #uuid "95d35c63-658f-4c24-a9bc-6452dfeda882"
Ah, so if you were going to improve the lib, the current imple of rendering of that looks:
(defmethod form-field* ::dropdown [component form field-name & params]
(let [id (form-ident form)
selection (current-value form field-name)
cls (or (css-class form field-name) "form-control")
field (field-config form field-name)
optional? (= ::none (:input/default-value field))
options (:input/options field)]
(dom/select #js
{:name field-name
:className cls
:value selection
:onChange (fn [event]
(let [value (.. event -target -value)
field-info {:form-id id
:field field-name
:value value}]
(om/transact! component
`[(select-option ~field-info)
~@(get-on-form-change-mutation form field-name :edit)
~form-root-key])))}
(when optional?
(dom/option #js {:value ::none} ""))
(map (fn [{:keys [option/key option/label]}]
(dom/option #js {:key key :value key} label))
options))))
OR copy the dropdown rendering code, and add it to your own type of field…but that would be kinda silly
you can see params already there. Change it to {:keys [onChange]}
and then run the onChange
in the input
actually, I think you need to pass the value (optionally the event), because form fields support transform functions
Not sure, I'll get to this later today. Thanks - this forms stuff will become very good very soon. I'm forgetting CSS for the moment, next week...
just needs these little details, which are better written as we hit some use cases. I have not had the chance to use it much yet.
on dropdowns: If you set a default then it won’t show a “nothing” option. If you want it to show something like required, then just add an entry for “required” that your form validation won’t accept as a value.