jkk / formative

Web forms for Clojure and ClojureScript - rendering, parsing, and validating
208 stars 18 forks source link

Select options: only set selected attribute when its true #36

Closed swalkinshaw closed 7 years ago

swalkinshaw commented 10 years ago

The selected attribute for an option element was always being set to either true or false. This breaks the selected attribute rendering (at least in Chrome). Only one option should ever have the selected attribute.

See http://jsbin.com/suwojito/1/

Output:

user=> (build-opt-tag "foo" "bar" "foo")
[:option {:selected "true", :value "foo"} "bar"]
user=> (build-opt-tag "foo" "bar" "quux")
[:option {:value "foo"} "bar"]
iku000888 commented 7 years ago

@swalkinshaw Thanks for the PR and sorry for the long time silence. With the hope that you are still interested, could you elaborate on the expectation of the example you posted? (Sorry for my lack of knowledge)

swalkinshaw commented 7 years ago

Sure, the example I showed displays what can happen when selected is on every option element.

There's 3 dropdowns:

1: incorrect. The first option has selected=true but it's overruled by the last one with selected=false. 2: correct. Only one element has the selected attr.

  1. incorrect. Variation on the 1st one.

This PR just skips setting selected on all options which is not really valid.

iku000888 commented 7 years ago

@swalkinshaw

Thanks for taking the effort explaining this after such a long period of time. I would be really happy to take this PR.

swalkinshaw commented 7 years ago

Closing in favour of https://github.com/jkk/formative/pull/49