-
Notifications
You must be signed in to change notification settings - Fork 290
Scaffold
Scaffold is used to build out all our main form editing pages. At the heart of it is Backbone Forms that enables us to use schemas to render forms with very little effort. Scaffold wraps around Backbone Forms and offers us an API that can enable fieldsets, custom views, custom fields, custom templates and custom validators. It also manages overlays opened during editing forms and pulls down new schemas when plugins are configured.
This will build a form object that can be used to append and commit the Backbone Form object. To build a form:
var form = Origin.scaffold.buildForm({
model: contentObjectModel
});
If you would like a different schemaType from the _type
attribute you can pass in a schemaType
attribute when building a form.
var form = Origin.scaffold.buildForm({
model: contentObjectModel,
schemaType: 'menuSchema'
});
To add a custom field pass in the fieldName and the view. This creates a custom view that whenever this field is present in a schema it will use this instead of a standard Backbone Form input. Passing in overwrite
as a boolean will overwrite this custom view - this enables plugins to overwrite a core plugin custom view.
Origin.scaffold.addCustomField('Asset:image', ScaffoldAssetView);
// Schema property
"inputType": "Asset:image"
When building a custom view it's advised to follow this template: Backbone Forms Custom Editor
To add a custom validator pass in the name of the validator and the function you would like to validate the form input field. Scaffold and Backbone Forms use an array of validators so it's possible to have multiple validators on one input field.
Origin.scaffold.addCustomValidator('titleLength', function(value, formValues) {
var err = {
type: 'title',
message: 'Titles must be at least 3 characters long'
};
if (value.length < 3) return err;
})