diff --git a/frontend/resources/styles/main/partials/sidebar-element-options.scss b/frontend/resources/styles/main/partials/sidebar-element-options.scss index b3f555d76..68fab3ded 100644 --- a/frontend/resources/styles/main/partials/sidebar-element-options.scss +++ b/frontend/resources/styles/main/partials/sidebar-element-options.scss @@ -207,6 +207,9 @@ border-color: $color-gray-40; } + &.error { + border-color: $color-danger; + } } .input-select { diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs index 881b95236..c4e86847e 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/interactions.cljs @@ -199,8 +199,20 @@ change-url (fn [event] - (let [value (-> event dom/get-target dom/get-value)] - (update-interaction index #(cti/set-url % value)))) + (let [target (dom/get-target event) + value (dom/get-value target) + has-prefix? (or (str/starts-with? value "http://") + (str/starts-with? value "https://")) + value (if has-prefix? + value + (str "http://" value))] + (when-not has-prefix? + (dom/set-value! target value)) + (if (dom/valid? target) + (do + (dom/remove-class! target "error") + (update-interaction index #(cti/set-url % value))) + (dom/add-class! target "error")))) change-overlay-pos-type (fn [event] @@ -287,7 +299,9 @@ (when (cti/has-url interaction) [:div.interactions-element [:span.element-set-subtitle.wide (tr "workspace.options.interaction-url")] - [:input.input-text {:default-value (str (:url interaction)) + [:input.input-text {:type "url" + :placeholder "http://example.com" + :default-value (str (:url interaction)) :on-blur change-url}]]) (when (cti/has-overlay-opts interaction) diff --git a/frontend/src/app/util/dom.cljs b/frontend/src/app/util/dom.cljs index f2f6595bf..a207f570d 100644 --- a/frontend/src/app/util/dom.cljs +++ b/frontend/src/app/util/dom.cljs @@ -28,17 +28,6 @@ [e] (.-target e)) -(defn classnames - [& params] - (assert (even? (count params))) - (str/join " " (reduce (fn [acc [k v]] - (if (true? (boolean v)) - (conj acc (name k)) - acc)) - [] - (partition 2 params)))) - - ;; --- New methods (defn set-html-title @@ -294,10 +283,28 @@ (defn get-root [] (query globals/document "#app")) +(defn classnames + [& params] + (assert (even? (count params))) + (str/join " " (reduce (fn [acc [k v]] + (if (true? (boolean v)) + (conj acc (name k)) + acc)) + [] + (partition 2 params)))) + (defn ^boolean class? [node class-name] (let [class-list (.-classList ^js node)] (.contains ^js class-list class-name))) +(defn add-class! [node class-name] + (let [class-list (.-classList ^js node)] + (.add ^js class-list class-name))) + +(defn remove-class! [node class-name] + (let [class-list (.-classList ^js node)] + (.remove ^js class-list class-name))) + (defn child? [node1 node2] (.contains ^js node2 ^js node1))