Skip to content

Dropdown - How to get choices to re-render when it's a callback? #263

Closed

Description

@brancusi

Hi,

When using a callback for choices, and if something within that function should react to changes, the choices fn won't rerun leading to out of sync choices.

Example

(defn uom-drop-down
  [{:keys [uoms
           model
           update-fn
           create-fn]}]
  [:div
   
   [:p (str "Total UOMS: " (count uoms))] ;; <- This updates fine

   [single-dropdown
    :src (at)
    :width "150px"
    :filter-box? true
    :auto-complete? true
    :model model
    :label-fn (fn [val] (:label val))
    :id-fn (fn [val] val)
    :debounce-delay 0
    :on-change (fn [val]
                 (case (:type val)
                   :create (create-fn (:val val))
                   :select (update-fn [(:id val) val])))
    :choices (fn [{:keys [filter-text]} done _] ;; <- This never gets recalled even if uoms changes
               (let [results (query->suggestions uoms :label filter-text)]
                 (done (if (seq results)
                         results
                         [{:label (str "No match found. Create " filter-text) :val filter-text :type :create}]))))]])

uoms is getting passed in from the parent. If there is no match, we want to be able to create a new UOM and then have that be added to the list for future use. Currently this choices won't rerun if uoms is updated.

Any help on how I might get this to work much appreciated.

Thank you

Activity

  1. locked and limited conversation to collaborators on Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions