 (defn- hyphenation-add-ui []
   [:div.form-group
    [:button.btn.btn-default
-    {:on-click #(when (and @word (hyphenation-valid? @hyphenation))
+    {:on-click #(when (and (not (string/blank? @word))
+                           (hyphenation-valid? @hyphenation @word))
                   (add-hyphenation-pattern! {:word @word :hyphenation @hyphenation :spelling @spelling}))
      :disabled (when (or (string/blank? @word)
-                         (not (hyphenation-valid? @hyphenation))
+                         (not (hyphenation-valid? @hyphenation @word))
                          (= @hyphenation @suggested-hyphenation))
                  "disabled")}
     "Add"]])

   [:td word]
   [:td hyphenation]])

(defn- hyphenation-valid? [s]
  (and (not (string/blank? s))
       (string/includes? s "-")
       (re-matches #"[a-z\xDF-\xFF-]+" s)))

(defn- hyphenation-pattern-readonly-ui
  [word hyphenation start remove]


(defn- hyphenation-pattern-edit-ui
  [word new-hyphenation stop save]
  (let [valid? (hyphenation-valid? @new-hyphenation word)
        klass (if valid? "form-group" "form-group has-error")]
    [:tr
     [:td word]
     [:td
      [:div
       {:class klass}
       [:input.form-control
        {:type "text"
         :auto-focus true
         :on-change #(reset! new-hyphenation (-> % .-target .-value))
         :on-key-down #(case (.-which %)
                         27 (stop)
                         nil)
         :value @new-hyphenation}]
       (when-not valid?
         [:span.sr-only "(error)"])]]
     [:td
      [:div.btn-group
       [:button.btn.btn-default
        {:on-click save}
        [:span.glyphicon.glyphicon-ok {:aria-hidden true}] " Save"]
       [:button.btn.btn-default
        {:on-click stop}
        [:span.glyphicon.glyphicon-remove {:aria-hidden true}] " Cancel"]]]]))

(defn hyphenation-pattern-item-ui [{:keys [hyphenation] :as pattern}]
  (let [editing (reagent/atom false)
