ibm-js / delite

HTML Custom Element / Widget infrastructure
http://ibm-js.github.io/delite/
Other
68 stars 28 forks source link

Put <select> in a template with option selected giving error #419

Closed martinfitzg closed 9 years ago

martinfitzg commented 9 years ago

Hello all Creating a very basic widget using handlebars template. When I put the following in the template.

<select>
    <option selected="selected" value="">hello now</option>
    <option value="CA16">Reference Number</option>
</select>

I get the following the error

"Uncaught ReferenceError: selected is not defined"

if I remove the selected attribute from the option all works fine.

Any one got away around this ?

wkeese commented 9 years ago

Hmm, I'll take a look next week, as this sounds like a bug.

Perhaps it's interpreting "selected" as the name of a property. In that case, as a workaround, adding selected: true to your widget might help.

martinfitzg commented 9 years ago

Hi Bill, Thanks for that, tried it, but no joy.... I'll leave it with you....

Martin

wkeese commented 9 years ago

I looked at it some more. This seems to work:

<option selected value="">hello now</option>

as does this (but the first is preferable since it's standard HTML):

<option selected="true" value="">hello now</option>

The failure is happening because HTMLOption#selected is a boolean property, and for non-string properties (including boolean properties), handlebars.js will generate code like:

c1c1.selected = selected;

rather than:

c1c1.selected = "selected";

I guess I should add some code so that markup like selected=selected (and disabled=disabled, etc.) is treated the same way as selected=true and disabled=true.

wkeese commented 9 years ago

PS: Hmm, I guess <option selected> isn't working either. It doesn't throw an exception but it doesn't select the option either. Only <option selected=true> is currently working.

Regardless, I have a fix that I will check in shortly.

martinfitzg commented 9 years ago

Thanks Bill !!!!