Skip to content

Commit

Permalink
Remove id attribute from hidden _method form field.
Browse files Browse the repository at this point in the history
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 #130.
Workaround for weavejester/hiccup#109.
  • Loading branch information
mvitz committed Apr 3, 2015
1 parent 2bfc991 commit 0d402e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/statuses/views/form.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(ns statuses.views.form
(:require [hiccup.def :refer [defelem]]
[hiccup.util :refer [to-uri]]))

(defelem form-to
"Create a form that points to a particular method and route.
e.g. (form-to [:put \"/post\"]
...)"
[[method action] & body]
(let [method-str (.toUpperCase (name method))
action-uri (to-uri action)]
(-> (if (contains? #{:get :post} method)
[:form {:method method-str, :action action-uri}]
[:form {:method "POST", :action action-uri}
[:input {:type "hidden"
:name "_method"
:value method-str}]])
(concat body)
(vec))))
3 changes: 2 additions & 1 deletion src/statuses/views/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
(:require [clj-time.local :refer [format-local-time]]
[hiccup.core :refer [html]]
[hiccup.element :refer [link-to]]
[hiccup.form :refer [form-to hidden-field text-field]]
[hiccup.form :refer [hidden-field text-field]]
[statuses.configuration :refer [config]]
[statuses.routes :refer [avatar-path update-path
updates-path profile-path]]
[statuses.views.common :as common :refer [icon]]
[statuses.views.form :refer [form-to]]
[statuses.views.layout :as layout]))

(defn- button
Expand Down

0 comments on commit 0d402e6

Please sign in to comment.