Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-boolean attributes (per the HTML5 spec) are incorrectly removed by the attr binding when given boolean values #391

Closed
bramstein opened this issue Mar 14, 2012 · 2 comments

Comments

@bramstein
Copy link

When I use the attr binding to set the draggable (non-boolean) attribute it is removed completely from the DOM when the expression evaluates to false. This is incorrect as img and a elements are draggable by default, so it is impossible to set them to be not draggable using Knockout. I had a quick look at the attr binding code and it seems to always remove an attribute when its expression evaluates to false. This should only happen when the attribute is actually a boolean attribute. The following are all boolean attributes from the HTML5 spec grouped by the elements they are legal on:

  • all elements: hidden
  • script: async, defer
  • button: autofocus, formnovalidate, disabled
  • input: autofocus, formnovalidate, multiple, readonly, required, disabled, checked
  • keygen: autofocus, disabled
  • select: autofocus, multiple, required, disabled
  • textarea: autofocus, readonly, required, disabled
  • style: scoped
  • ol: reversed
  • command: disabled, checked
  • fieldset: disabled
  • optgroup: disabled
  • option: selected, disabled
  • audio: autoplay, controls, loop, muted
  • video: autoplay, controls, loop, muted
  • iframe: seamless
  • track: default
  • img: ismap
  • form: novalidate
  • details: open
  • object: typemustmatch
  • marquee: truespeed

Is is possible for Knockout to only remove attributes when the attr binding expression evaluates to false and the attribute is an actual boolean attribute?

@mbest
Copy link
Member

mbest commented May 11, 2012

Can you use data-bind="attr: { draggable: 'false' }"?

@mbest
Copy link
Member

mbest commented Dec 14, 2012

Closing, as this is something we're not likely to include in Knockout.

@mbest mbest closed this as completed Dec 14, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants