Created
January 30, 2016 20:07
-
-
Save Bondifrench/e684460451e643190795 to your computer and use it in GitHub Desktop.
A select element for Mithril from @JAForbes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
})); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A select element. Receives a list of options and a prop for persistence