Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 innoq#130.
Workaround for weavejester/hiccup#109.
mvitz committed Apr 22, 2015

Verified

This commit was signed with the committer’s verified signature.
fengmk2 fengmk2
1 parent 3600148 commit 601a33e
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
@@ -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

0 comments on commit 601a33e

Please sign in to comment.