Middleware

You can add a middleware to modify the behaviour of the inbuilt actions provided by Formst. For example, you can modify a form value by intercepting the setValue action.

Formst exports addMiddleware from MobX state tree. You can refer to their documentation for detailed usage and API details.

Usage#

const TodoForm = createFormModel(
'TodoForm',
{
title: types.string,
description: types.string,
},
...
);
addMiddleware(TodoForm, (call, next, abort) => {
if (call.name === 'setValue') {
const fieldName = call.args[0];
if (fieldName === 'title') {
call.args[1] = call.args[1].toUpperCase();
}
}
next(call);
});

To get all the available actions for a form model, refer to the source code.