MobxSchemaForm

MobxSchemaForm is a React component which renders form fields as declared in json schema config object it receives. It supports the following props:

* = feature not present in react-schema-form. ** = new feature in v1.6. *** = new feature in v1.7. **** = new feature in v1.8.

model.fields

MobxSchemaForm will create a fields property on the model object when MobxSchemaForm mounts (unless it already exists). For each currently mounted form field there will be a key in model.fields. The name of each key is the modelKey in the corresponding schema.properties object if defined or just the schema.propreties key. Each key references a formField object in the formShape format which is a specially merged combination of the Form Field Metadata and the corresponding Data Property Schema.

It is often desired to call model.refresh() when MobxSchemaForm mounts to retrieve from server existing data that needs to be edited in the form. Be sure to do this in componentDidMount() of your form so that model.fields are in place when the FormStore afterRefresh callback runs, so that this callback can do:

const onlyWithValues = true;
validateForm(store.fields, store, onlyWithValues);

This runs form-wide validation on already filled fields (though usually server won't return invalid data back) but more importantly it will also re-populate model.data properties that got 'refreshed' with null to defaults defined in the schema.

Note that starting with v1.6, if you mount multiple instances of MobxSchemaForm against the same FormStore model, whole-form validation will validate all fields from all mounted instances that use this model.

model.validators

MobxSchemaForm will merge options.validators object it receives if any into model.validators.

Last updated