extendFormBinding
extendFormBinding<
Bindings>(bindings):Bindings
Defined in: binding.ts:250
Add a bind method to every form for each binding class
A method binds its class to the form it is called on with Form.bind. It takes the field name (or the list of field names, or nothing for a binding to the form) and the config, and an omitted config becomes an empty object.
Type the methods by extending Form with FormBindingMethods:
Type Parameters
Section titled “Type Parameters”Bindings
Section titled “Bindings”Bindings extends Record<string, new (...args: any) => unknown>
Parameters
Section titled “Parameters”bindings
Section titled “bindings”Bindings
Binding classes by method name. Each name is bind followed by a capital letter.
Returns
Section titled “Returns”Bindings
bindings as is, for typing the methods with FormBindingMethods
Example
Section titled “Example”export const myBindings = extendFormBinding({ bindDropdown: DropdownBinding,});
declare module "@mobx-sentinel/form" { interface Form<T> extends FormBindingMethods<T, typeof myBindings> {}}<Dropdown {...form.bindDropdown("country", { getter: () => model.country, setter: (v) => (model.country = v) })} />Remarks
Section titled “Remarks”- Forms created before the call get the methods too
- Adding a method under a name that is already taken replaces it on every form
- The methods are shared by every form, like the methods of a class, so a method detached from its form fails
Throws
Section titled “Throws”TypeError if a name does not start with bind and a capital letter, or a binding is not a class.
No method is added then.