started working on validation on action form.

This commit is contained in:
Bryce Covert
2018-05-23 12:07:51 -07:00
parent a3762a76af
commit 0611c169c7
6 changed files with 51 additions and 8 deletions

View File

@@ -2,7 +2,7 @@
(:require [reagent.core :as r]
[clojure.string :as str]))
(defn typeahead [{:keys [matches on-change field value]}]
(defn typeahead [{:keys [matches on-change field value class]}]
(let [text (r/atom (or (second (first (filter #(= (first %) value) matches))) ""))
highlighted (r/atom 0)
selected (r/atom (first (first (filter #(= (first %) value) matches))))
@@ -12,19 +12,20 @@
(println [id t])
(when on-change
(on-change id)))]
(fn [{:keys [matches on-change field value]}]
(fn [{:keys [matches on-change field value class]}]
(let [valid-matches (take 5 (for [[[id t :as match] i] (map vector matches (range))
:when (str/includes? (.toLowerCase t) (.toLowerCase @text))]
match))]
[:div.typeahead
(if @selected
[:div.input
[:div.input {:class class}
[:div.control
[:div.tags.has-addons
[:span.tag @text]
[:a.tag.is-delete {:on-click (fn [] (select [nil ""]))}]]]]
[:input.input {:type "text"
:class class
:field [:vendor]
:value @text
:on-blur (fn [e]