weavejester / hiccup

Fast library for rendering HTML in Clojure
http://weavejester.github.io/hiccup
Eclipse Public License 1.0
2.66k stars 174 forks source link

disabled value in HTML FORM #162

Closed damien-mattei closed 4 years ago

damien-mattei commented 4 years ago

hello, i try this :+1: €‹[:form {:action "/action_page.php"} "\n Last name: " [:input {:type "text", :name "lname", :disabled }] [:br] [:input {:type "submit", :value "Submit"}]]" "

from: http://html2hiccup.buttercloud.com/

the : disabled failed to compile:

[mattei@moita eu.oca.jclojure]$ lein uberjar Compiling eu.oca.jclojure java.lang.RuntimeException: Map literal must contain an even number of forms, compiling:(eu/oca/jclojure.clj:256:138) Exception in thread "main" java.lang.RuntimeException: Map literal must contain an even number of forms, compiling:(eu/oca/jclojure.clj:256:138) at clojure.lang.Compiler.compile(Compiler.java:7639)

in my code i use:

(ns eu.oca.jclojure (:gen-class :name eu.oca.jclojure :methods [

^{:static true} [binomial [int int] double]

           #^{:static true} [banner [String] String]
           #^{:static true} [testLog [String] String]
           #^{:static true} [InterfaceNomResourceClojure [String] String]
           #^{:static true} [UpdateDBResourceClojure [String String String String String String String String String String String String String String String String] String]
           ]
 )
(:require [clojure.java.jdbc :as jdbc]
          [clojure.string]
          [infix.macros :refer [infix]])

(:use [hiccup.core] ;; core,form not needed
      [hiccup.page]
      [hiccup.form]))

in the project.clj:

(defproject eu.oca.jclojure "0.1.0-SNAPSHOT" :description "library clojure JVM source code for Sidonie web interface administration" :url "https://sidonie.oca.eu" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.8.0"] [mysql/mysql-connector-java "5.1.38"] [org.clojure/java.jdbc "0.7.3"] [hiccup "1.0.5"] [rm-hull/infix "0.3.3"]] :aot :all :main eu.oca.jclojure )

;; create the interface in HTML to modify Astro data (defn create-html-body-OK [mag1 mag2 hh mmDOTm dd mm record Nom] [:body [:p {:style "margin-bottom: 0cm", :align "center"} [:br]] [:p {:style "margin-bottom: 0cm", :align "center"} [:font {:style "font-size: 15pt", :size "4"} [:font {:style "font-size: 18pt", :size "5"} "Modification des identifications d'un systéme binaire"]" "]] [:p {:style "margin-bottom: 0cm", :align "center"} [:br]] [:p {:style "margin-bottom: 0cm", :align "center"} [:br]] [:form {:name "Form", :action "../jersey/UpdateDB" :method "POST"}
[:table {:style "page-break-before: always; page-break-inside: avoid", :width "100%", :cellspacing "1", :cellpadding "4"}
[:colgroup [:col {:width "64*"}]] [:tbody [:tr {:valign "top"}
[:td {:style "border-top: 1px double #808080; border-bottom: 1px double #808080; border-left: 1px double #808080; border-right: none; padding-top: 0.1cm; padding-bottom: 0.1cm; padding-left: 0.1cm; padding-right: 0cm", :width "25%"}
[:div {:align "center"}
[:p [:font {:color "#00cccc"} "N° de fiche " [:input {:name "No_Fiche", :value (:n°_fiche record), :size "8", :style "width: 2cm; height: 0.93cm", :type "text", :disabled}]]]]]

:disabled does not works?

damien-mattei commented 4 years ago

finally find a solution: :disabled "true" it generates not a single disabled in HTML but a disabled="true" that works fine.

damien-mattei commented 4 years ago

works at least in firefox, i did not try others, but HTML validator : https://validator.w3.org/ give this : Error: Bad value true for attribute disabled on element input.

weavejester commented 4 years ago

Try:

(html {:mode :html} [:input {:type "text", :name "lname", :disabled true}])

This will render as:

<input disabled name="lname" type="text">

You should also set a doctype. If you want HTML5, you can use the html5 macro to automatically add a doctype and surrounding <html> tags.