Level: beginner • Mithril.js Version: latest
form input m.mount radiobutton
Handling radio and checkboxes is often a little bit special. This example demonstrates how to use radio buttons in a Mithril.js application.
Type | Name | URL |
---|---|---|
script | mithril@latest | https://unpkg.com/mithril@latest |
const model = {
yesno: "Yes"
}
const app = {
view: () => [
m('h1', "Radio"),
["Yes", "No"].map(x =>
m('label',
m('input', {
type: 'radio',
id: x,
name: 'test',
checked: model.yesno === x,
onchange: () => model.yesno = x,
value: x
}),
x
)
)
]
}
m.mount(document.body, app)
label {
display: block
}
The snippet is using the most current version of Mithril.js framework. It is aimed at beginners and shows some basic recipes.
In addition to the Mithril.js hyperscript function m(), here we can see an example of Mithril.js' m.mount
API method.
The example was contributed by osban and last modified on 24 September 2020. Click here to see more examples contributed by the author.
If anyone has some improvements, that should be addressed, let me know by opening an issue. Or simply fork the repository on GitHub, push your commits and send a pull request. For starting your work, you can click the edit link below. Thanks for contributing.