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

Select with {key: value} style options #21

Merged
merged 1 commit into from
Jul 3, 2019

Conversation

zdenko
Copy link
Contributor

@zdenko zdenko commented Feb 25, 2018

This PR enables use of key: value style options for the select field. And, as a bonus, adds Coffeescript 2.

template = makeTemplate """
  select(@value @options)
"""

options = Observable
  nap: "Napoleon"
  bar: "Barrack"

model =
  options: options
  value: "bar"

select = template model

assert.equal select.value, "bar"

# adding an option
options Object.assign {}, options(), {test: "Test"}
assert.equal select.querySelectorAll("option").length, 3

# deleting an option
delete options().test
options Object.assign {}, options()
assert.equal select.querySelectorAll("option").length, 2

Observable value

template = makeTemplate """
  select(@value @options)
"""

options = Observable
  nap: Observable "Napoleon"
  bar: Observable "Barrack"

model =
  options: options
  value: "bar"

select = template model

optionElements = select.querySelectorAll("option")
assert.equal optionElements[1].textContent, "Barrack"
options().bar "YOLO"
assert.equal optionElements[1].textContent, "YOLO"

With the PR from distri/observable adding and deleting option can be shorter:

# adding an option
options.extend {test: "Test"}

# deleting an option
options.remove "test"

@zdenko zdenko mentioned this pull request Jun 28, 2018
@STRd6 STRd6 merged commit de06d2e into STRd6:master Jul 3, 2019
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

Successfully merging this pull request may close these issues.

2 participants