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

Simplify markup for select elements #709

Open
awidener3 opened this issue Nov 18, 2024 · 0 comments
Open

Simplify markup for select elements #709

awidener3 opened this issue Nov 18, 2024 · 0 comments
Assignees
Labels
enhancement Planned feature

Comments

@awidener3
Copy link
Contributor

awidener3 commented Nov 18, 2024

Investigate ways to reduce the markup needed when writing select elements when the value exists in the model.

For example, perhaps a setup below will take the <select> element value and automatically apply the selected attribute to a matching option element.

// data passed to teddy template
const model = {
  foo: 'b'
}
<!-- teddy template -->
<select selected-value="{foo}" ...>
  <option value="a">A</option>
  <option value="b">B</option> <!-- this receives the "selected" attribute on render -->
  <option value="c">C</option>
</select>

<!-- rendered result -->
<select ...>
  <option value="a">A</option>
  <option value="b" selected>B</option>
  <option value="c">C</option>
</select>

The value attribute would also need to be removed from the <select> element, since it is not a valid attribute for the element.

It could also be extended to looped options:

const model = {
  foo: ['a', 'b', 'c'],
  selected: 'b'
}
<select selected-value="{selected}">
  <loop through="foo" val="letter">
    <option value="{letter}">{letter}</option>
  </loop>
</select>

For reference, this is how the first example is currently achieved:

<select ...>
  <option value="a" if-foo="a" true="selected">A</option>
  <option value="b" if-foo="b" true="selected">B</option>
  <option value="c" if-foo="c" true="selected">C</option>
</select>

Needs to handle checkboxes and radio buttons too though which is a trickier problem.

@kethinov kethinov transferred this issue from rooseveltframework/semantic-forms Nov 18, 2024
@kethinov kethinov self-assigned this Nov 18, 2024
@kethinov kethinov added the enhancement Planned feature label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Planned feature
Development

No branches or pull requests

2 participants