Level: beginner • Mithril.js Version: latest
3rd-party dom form m.mount oncreate select
This example shows the integration of select2 3rd-party library. Whit it it's possible to search for an item and use the up/down keys to select an item.
Type | Name | URL |
---|---|---|
script | mithril@latest | https://unpkg.com/mithril@latest |
script | jquery@3.3.1 | https://unpkg.com/jquery@3.3.1 |
script | select2@4.0.6-rc.1 | https://unpkg.com/select2@4.0.6-rc.1 |
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
const App = {
view: () => m('div', [
m('p', 'my select'),
m('select', {
name: 'states',
oncreate: ({dom}) => $(dom).select2()
}, [
m('option', { value: 'AL' }, 'Alabama'),
m('option', { value: 'WI' }, 'Wisconsin')
])
])
};
m.mount(document.body, App)
The snippet requires the latest version of Mithril.js framework. It is ideal for beginners showing some basic recipes.
In this example we can see an example of Mithril.js' m.mount
API method, besides it core m() hyperscript function.
It is also showing the oncreate
hook, which is one of several Mithril.js' lifecycle methods.
The code sample was authored by kevinfiol. It was last modified on 26 October 2021. Want to see more examples written by kevinfiol? Then Click here.
Do you see some improvements, that could be addressed here? Then let me know by opening an issue. As an alternative, you can fork the repository on GitHub, push your commits and send a pull request. To start your work, click on the edit link below. Thank you for contributing to this repo.