From a3ef5b6e7f6a71a8c43faa65c631f5e15b427d61 Mon Sep 17 00:00:00 2001 From: Michael Vitz Date: Fri, 13 Mar 2015 09:25:50 +0100 Subject: [PATCH] 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 #130. Workaround for weavejester/hiccup#109. --- src/statuses/views/form.clj | 19 +++++++++++++++++++ src/statuses/views/main.clj | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/statuses/views/form.clj diff --git a/src/statuses/views/form.clj b/src/statuses/views/form.clj new file mode 100644 index 0000000..d48ecde --- /dev/null +++ b/src/statuses/views/form.clj @@ -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)))) diff --git a/src/statuses/views/main.clj b/src/statuses/views/main.clj index adacb00..db11780 100644 --- a/src/statuses/views/main.clj +++ b/src/statuses/views/main.clj @@ -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