Skip to content

Commit d9efd5f

Browse files
committed
Remove id attribute from hidden _method form field.
By default hiccup generates an id for every form field. In our case (more than one form with method DELETE on the same page) this leads to non unique ids which leads to w3c validation errors. Relates to innoq#130. Workaround for weavejester/hiccup#109.
1 parent a6f81e9 commit d9efd5f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/statuses/views/form.clj

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(ns statuses.views.form
2+
(:require [hiccup.def :refer [defelem]]
3+
[hiccup.util :refer [to-uri]]))
4+
5+
(defelem form-to
6+
"Create a form that points to a particular method and route.
7+
e.g. (form-to [:put \"/post\"]
8+
...)"
9+
[[method action] & body]
10+
(let [method-str (.toUpperCase (name method))
11+
action-uri (to-uri action)]
12+
(-> (if (contains? #{:get :post} method)
13+
[:form {:method method-str, :action action-uri}]
14+
[:form {:method "POST", :action action-uri}
15+
[:input {:type "hidden"
16+
:name "_method"
17+
:value method-str}]])
18+
(concat body)
19+
(vec))))

src/statuses/views/main.clj

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
(:require [clj-time.local :refer [format-local-time]]
33
[hiccup.core :refer [html]]
44
[hiccup.element :refer [link-to]]
5-
[hiccup.form :refer [form-to hidden-field text-field]]
5+
[hiccup.form :refer [hidden-field text-field]]
66
[statuses.configuration :refer [config]]
77
[statuses.routes :refer [avatar-path update-path
88
updates-path profile-path]]
99
[statuses.views.common :as common :refer [icon]]
10+
[statuses.views.form :refer [form-to]]
1011
[statuses.views.layout :as layout]))
1112

1213
(defn- button

0 commit comments

Comments
 (0)