Skip to content

Forms Composer

Forms composer is an useful helper that can be used to manage a group of related Froms instances. For example we have multiple forms and each of them is a part of a multi-step application. With the composer you can execute some actions on all forms at same time.

How to use Composer

javascript
import { composer } from 'mobx-react-form/lib/composer';

const forms = composer({
    formA: new FormA({ ...formDefinitionsA }),
    formB: new FormB({ ...formDefinitionsB }),
    formC: new FormC({ ...formDefinitionsC }),
});

Each Form instance have to be a MobxReactForm instance.

Available Methods

MethodInputOutputInfoHelp
instances()-objectGet the plain object with forms instances.-
select(key)stringFormSelect a form by object key.-
check(prop)stringobjectReturn an object with a boolean of the checked prop for each form.-
get(prop)stringobjectReturn an object with a value of the getted prop for each form.-
valid()-booleanCheck if all forms are valid.-
error()-booleanCheck if all forms has errors.-
clear()-voidClear all forms.-
clear({ deep, execHook })-voidClear all forms (with options).-
reset()-voidReset all forms.-
reset({ deep, execHook })-voidReset all forms (with options).-
validate()-PromiseValidate all forms.-
validate({ showErrors })-PromiseValidate all forms (with options).-
submit()-PromiseSubmit all forms.-
submit({ validate, execOnSubmitHook, execValidationHooks })-PromiseSubmit all forms (with options).-

The Promises resolves an object with the forms status and the composer functions

Released under the MIT License.