Search code examples
clojuredialogseesaw

How to get the dialog functions work


I want to open a dialog, and work with the data after the the dialog returns ok. The problem is that :success-fn is not called after the dialog is submitted. That has something to do with the listener from the button. If the connectDialog is called without listener, the function of :success-fn is called.

Code:

(def dbConnectionForm
  (grid-panel :columns 2
              :items ["Database Driver" (combobox :id :dbdriver :model ["postgresql" "mysql"])
                      "Database"        (text :id :dbname :text "postgres")
                      "Port"            (text :id :dbport :text "32768")
                      "Username"        (text :id :username :text "postgres")
                      "Password"        (text :id :password :text "postgres")]))

(defn connectionDialog []
  (print (-> (dialog
    :content dbConnectionForm
    :option-type :ok-cancel
    :type :plain
    :success-fn (fn [e] (print (value dbConnectionForm)))
    )pack! show!))
  )

(def connectButton (button :text "Connect"
                           :listen [:action (fn [e] (connectionDialog))]))

Solution

  • This is probably because you're using print. Change it to println or add a call to flush inside the callback after the print.

    If (value dbConnectionForm) returns a small value (as in something that when turned into a String has only a few characters), and doesn't contain newlines, it might not prompt the outstream to automatically flush, so the text gets stuck in the buffer.