Skip to main content

form.converter

FormConverter : d2/sdk/controls/form/form.converter

Form converter. Utility to transform D2 Form metadata.

Extends: Object

FormConverter.convertConfig(formJSON, options) ⇒ ConversionReturnType

Convert a D2 Form metadata into an Alpaca form schema.

Kind: static method of FormConverter
Returns: ConversionReturnType - propertiesConfig & signOffConfig are two separate alpaca form schema to collect properties and user's electronic signature.
Note: Alpaca form schema generated through this method does not have to go through generateFormModelConfig() method below.
See: Alpaca Forms

ParamTypeDescription
formJSONJSON

Raw dialog-like response received from a D2-REST API or an equivalent object constructed literally.

optionsObject

Holder of transformer parameters

[options.actionMode]string

How to process the fields. Can be one of 'create', 'read', 'edit'. 'read' is for readonly mode, other two are editable. Value of this option influences the list of fields and their conditions processed as per equivalent D2-config property page field modes.

[options.layoutMode]string

By default fields are laid out in a double column fashion, if a single-column is desired instead set this option to 'singleCol'.

FormConverter.generateFormModelConfig(formArray, [options]) ⇒ void

Inject additional data into an Alpaca form schema and make it compatible for FormModel & FormView. If more than one form is passed in the input, the method also generates cross-reference data if one form uses value from other, for any reason.

Kind: static method of FormConverter

ParamTypeDescription
formArrayArray.<AlpacaSchema>

Array of Alpaca form schemas. The parameter is also the output parameter, each element in the array is modified with additional data.

[options]object

Additional data/control flag used during the conversion.

[options.initialFieldValueMap]object

Initial data reference for all the fields across forms.

FormConverter~ConversionReturnType : Object

Kind: inner typedef of FormConverter
Properties

NameTypeDescription
propertiesConfigObject

Alpaca schema for the main form

signOffConfigObject

Alpaca schema for D2 Electronic signature form

FormConverter~AlpacaSchema : Object

Kind: inner typedef of FormConverter
See: Alpaca Forms
Properties

NameTypeDescription
dataobject

Object hash of initial values for each field property

schemaobject

Container of schema properties

schema.propertiesobject

Object hash defining schema for each field property.

optionsobject

Container of additional options

options.fieldsobject

Object hash defining options for each field property.

Example

var form = {
data: {
field1: 'Hello world!'
},
schema: {
properties: {
field1: {
type: 'string',
required: true
}
}
},
options: {
fields: {
field1: {
type: 'text',
label: 'Greetings'
}
}
}
};