Skip to content

Instantly share code, notes, and snippets.

@yosevu
Created April 6, 2018 12:13
Show Gist options
  • Select an option

  • Save yosevu/30e4eee843c69d8d75a4a1b7a77dc681 to your computer and use it in GitHub Desktop.

Select an option

Save yosevu/30e4eee843c69d8d75a4a1b7a77dc681 to your computer and use it in GitHub Desktop.
Hot Dog Stand in Browser: renderOptions()
// Before
this.renderOptions(item, name, this.menuItems[name]);
renderOptions(item, name, { options, required, onlyOne }) {
options.forEach((option, i) => {
item.innerHTML += `
<label class="option" for="${option}">
<input
id="${option}"
name="${name}"
${required}
type=${onlyOne ? 'radio' : 'checkbox'}
value="${option}"
>
${option}
</label>
`;
});
}
// After
item.innerHTML += this.renderOptions(name, this.menuItems[name]).join('');
renderOptions(name, { options, required, onlyOne }) {
return options.map((option, i) => (`
<label class="option" for="${option}">
<input
id="${option}"
name="${name}"
${required}
type=${onlyOne ? 'radio' : 'checkbox'}
value="${option}"
>
${option}
</label>
`)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment