weavejester / hiccup

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

Generate correct markup for selected options. #50

Closed emezeske closed 12 years ago

emezeske commented 12 years ago

Previously, each

Note that I also amended the tests to make sure that this works properly.

weavejester commented 12 years ago

Hiccup interprets boolean values in attributes differently from strings:

user> (select-options [1 2 3] 3)
([:option {:selected false} 1] [:option {:selected false} 2] [:option {:selected true} 3])

user> (html (select-options [1 2 3] 3))
"<option>1</option><option>2</option><option selected=\"selected\">3</option>"

user> (html [:option {:selected true} 3])
"<option selected=\"selected\">3</option>"

user> (html [:option {:selected false} 1])
"<option>1</option>"

So the behaviour is already correct. No need for this patch.

emezeske commented 12 years ago

Interesting! I ran into this problem with crate, first, and fixed it there before cross-porting the fix to hiccup. I assumed that it was a problem here too, because I did not know about this behavior.

I patched it the same way in crate. Now I'm thinking that I should take a look at crate's boolean attribute handling, which (I guess) does not work this way. I probably should fix that instead of handling things specially for select-options.

Thanks for the quick feedback on this!