Skip to content

Instantly share code, notes, and snippets.

@Bondifrench
Created January 30, 2016 20:07
Show Gist options
  • Save Bondifrench/e684460451e643190795 to your computer and use it in GitHub Desktop.
Save Bondifrench/e684460451e643190795 to your computer and use it in GitHub Desktop.
A select element for Mithril from @JAForbes
var select = function select(options, prop, attr) {
if (typeof prop() == "undefined" || prop() == "") {
prop(options[0]);
}
if (options.length == 0) {
prop("");
}
return m("select.form-control", _.extend({
onchange: prop && m.withAttr("value", prop),
disabled: options.length == 0,
value: prop() //((options.length == 0)?(""):(prop()))
}, attr), options.map(function (option) {
return m("option", { value: option }, _.trunc(_.capitalize(option), 16));
}));
};
@Bondifrench
Copy link
Author

A select element. Receives a list of options and a prop for persistence

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment