Skip to content

inconsistent interpretation of html spec in handling of input "checked" attribute #1075

@tomconnors

Description

@tomconnors

Bug Report

  • datastar special cases the "value" attribute of input elements; when patching elements, if an <input> has a changed "value", a corresponding change is made to the input's value property.
  • datastar does not similarly special case the "checked" attribute of input elements; when patching elements, if an input's "checked" attribute has changed, the input's "checked" property is not updated.
  • "value" and "checked" are similarly defined in the html spec (https://html.spec.whatwg.org/#attr-input-value); the spec suggests no reason d* should handle them differently.

A change that that would resolve this inconsistency:

  • datastar should special-case the input attributes "checked" and "disabled" the same way it currently special cases "value".
  • datastar should also special case the <option> "selected" attribute, which is described in the html spec similarly to input.value and input.checked.
  • in case it's helpful, this file shows what elements and attributes morphdom handles specially: https://github.com/patrick-steele-idem/morphdom/blob/master/src/specialElHandlers.js

These changes would simplify the HTML included in some patch-elements events. Instead of toggling a checkbox with:

<input type="checkbox" data-on-load="el.checked = true;" />

users could write:

<input type="checkbox" checked />

This also seems like a more intuitive behavior. It seems unlikely someone would send down <input type="checkbox" checked /> and only want to change the default checkedness of the input.

Datastar Version

v1 rc 5

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions