Skip to content

Instantly share code, notes, and snippets.

@erikvullings
Created November 3, 2024 11:56
Show Gist options
  • Save erikvullings/aa531ff3255dad0b0b207df4ff6c04e4 to your computer and use it in GitHub Desktop.
Save erikvullings/aa531ff3255dad0b0b207df4ff6c04e4 to your computer and use it in GitHub Desktop.
Plugin for mithril-ui-form of the SearchSelect component
import { registerPlugin } from 'mithril-ui-form';
import { searchSelectPlugin } from './search-select-plugin';
// Register plugin under the name `search_select` or any other name of your choosing.
registerPlugin('search_select', searchSelectPlugin);
import m from 'mithril';
import { PluginType } from 'mithril-ui-form';
import { SearchSelect, Option } from 'mithril-materialized';
export const searchSelectPlugin: PluginType<string[], Option<string>[]> = () => {
let options: Option<string>[] = [];
let className: string | undefined;
return {
oninit: ({ attrs: { field } }) => {
const { options: o, className: c } = field;
className = c;
if (o && typeof o !== 'string') {
options = o;
}
},
view: ({ attrs: { iv, onchange, label } }) => {
return m(
'.multi-select',
{ className },
m(SearchSelect<string>, {
label,
initialValue: iv,
options,
onchange,
})
);
},
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment