Skip to content

Commit f16db76

Browse files
committed
feat: Reintroduced additional events handling
Removed unused imports and introduced 'additionalEvents' property to FormAttributes in Form.tsx. This allows for dynamic binding of events to the form, enhancing component's flexibility. A loop has been added in the view function to bind these additional events.
1 parent 9a51890 commit f16db76

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Form.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import m, {
2-
ChildArray,
3-
Children,
42
Vnode,
53
VnodeDOM
64
} from 'mithril';
@@ -13,7 +11,8 @@ export type FormSubmitEvent = SubmitEvent & {data: FormData};
1311
export interface FormAttributes extends Partial<Omit<HTMLElementTagNameMap['form'], 'style' | 'onsubmit'>> {
1412
onsubmit?: (event: FormSubmitEvent) => void,
1513
state?: Record<string, Stream<string | any>> | Map<string, Stream<string | any>>
16-
additionalElementsSelector?: string
14+
additionalElementsSelector?: string,
15+
additionalEvents?: string[]
1716
}
1817

1918
export type FormInputAttributes = HTMLElementTagNameMap['input'] & {
@@ -47,6 +46,9 @@ export default class Form<A extends FormAttributes = FormAttributes> extends Com
4746

4847
view(vnode: Vnode<A>) {
4948
const attrs = this.attrs.except(['onsubmit', 'state', 'additionalElementsSelector']);
49+
for (const event of vnode.attrs.additionalEvents ?? []) {
50+
attrs.put(event, this.onsubmit.bind(this))
51+
}
5052
return (
5153
<form {...attrs.all()} onsubmit={this.onsubmit.bind(this)} oninput={this.oninput.bind(this)}>
5254
{vnode.children}

0 commit comments

Comments
 (0)