aem-forms-af-runtime

@aemforms/af-core - v0.22.76

Table of contents

Interfaces

Classes

Type aliases

Variables

Enumerations

Functions

Type aliases

BaseJson

Ƭ BaseJson: TranslationBaseJson & RulesJson & ConstraintsJson & { :type?: string ; altText?: string ; appliedCssClassNames?: string ; constraintMessages?: ConstraintsMessages ; dataRef?: string | null ; enabled?: boolean ; errorMessage?: string ; fieldType?: string ; label?: Label ; lang?: string ; name?: string ; properties?: { [key: string]: any; } ; repeatable?: boolean ; screenReaderText?: string ; tooltip?: string ; viewType?: string ; visible?: boolean }

Type for generic form properties based on adaptive form specification


ChangePayload

Ƭ ChangePayload: Object

Payload of change event

Type declaration

Name Type Description
changes { currentValue: any ; prevValue?: any ; propertyName: string }[] List of changes

ConstraintsJson

Ƭ ConstraintsJson: TranslationConstraintsJson & { accept?: string[] ; enforceEnum?: boolean ; exclusiveMaximum?: number ; exclusiveMinimum?: number ; format?: string ; maxFileSize?: number | string ; maxItems?: number ; maxLength?: number ; maxOccur?: number ; maximum?: number ; minItems?: number ; minLength?: number ; minOccur?: number ; minimum?: number ; pattern?: string ; required?: boolean ; step?: number ; type?: string ; uniqueItems?: boolean ; validationExpression?: string }

Type for constraint properties based on adaptive form specification


ConstraintsMessages

Ƭ ConstraintsMessages: Object

Type for constraint messages based on adaptive form specification

Type declaration

Name Type
accept? string
enum? string
exclusiveMaximum? string
exclusiveMinimum? string
format? string
maxFileSize? string
maxItems? string
maxLength? string
maximum? string
minItems? string
minLength? string
minimum? string
pattern? string
required? string
step? string
type? string
uniqueItems? string
validationExpression? string

ContainerJson

Ƭ ContainerJson: BaseJson & { activeChild?: string ; initialItems?: number ; items: (FieldJson | ContainerJson)[] }

Type for form container properties based on adaptive form specification


EnumName

Ƭ EnumName: Object

Type for enumNames based on adaptive form specification

Type declaration

Name Type
richText? boolean
value string

FieldJson

Ƭ FieldJson: BaseJson & TranslationFieldJson & { checked?: boolean ; default?: any ; displayFormat?: string ; displayValue?: string ; displayValueExpression?: string ; editFormat?: string ; editValue?: string ; emptyValue?: "null" | "undefined" | "" ; readOnly?: boolean ; valid?: boolean ; validationMessage?: string ; validity?: any ; value?: any }

Type for form field properties based on adaptive form specification


FieldsetJson

Ƭ FieldsetJson: ContainerJson & { readOnly?: boolean ; type?: "array" | "object" }

Type for form fieldset based on adaptive form specification


FormCreationMode

Ƭ FormCreationMode: "create" | "restore"


FormJson

Ƭ FormJson: ContainerJson & { action?: string ; adaptiveForm?: string ; data?: any ; lang?: string ; metadata?: MetaDataJson ; title?: string }

Type for form model based on adaptive form specification


Items

Ƭ Items<T>: Object

Type for items property based on adaptive form specification

Type parameters

Name
T

Index signature

▪ [key: string]: T


Label

Ƭ Label: Object

Type for label based on adaptive form specification

Type declaration

Name Type
richText? boolean
value string
visible? boolean

MetaDataJson

Ƭ MetaDataJson: Object

Type for form metadata based on adaptive form specification

Type declaration

Name Type
grammar? string
version? string

Primitives

Ƭ Primitives: string | number | boolean | null | undefined

Type alias for primitive types


RulesJson

Ƭ RulesJson: Object

Type for constraint messages based on adaptive form specification

Type declaration

Name Type
events? Items<string[] | string | undefined>
rules? Items<string>

State

Ƭ State<T>: stateProps & T extends ContainerJson ? T & { items: State<FieldJson | ContainerJson>[] } : T

Generic type for a form object state

Type parameters

Name
T

TranslationJson

Ƭ TranslationJson: TranslationBaseJson & TranslationFieldJson & TranslationConstraintsJson

Type for all properties which can be translated based on adaptive form specification

Variables

CUSTOM_PROPS_KEY

CUSTOM_PROPS_KEY: "properties"


ConstraintType

ConstraintType: Readonly<{ ACCEPT_MISMATCH: "acceptMismatch" = ‘acceptMismatch’; EXPRESSION_MISMATCH: "expressionMismatch" = ‘expressionMismatch’; FILE_SIZE_MISMATCH: "fileSizeMismatch" = ‘fileSizeMismatch’; FORMAT_MISMATCH: "formatMismatch" = ‘formatMismatch’; MAX_ITEMS_MISMATCH: "maxItemsMismatch" = ‘maxItemsMismatch’; MIN_ITEMS_MISMATCH: "minItemsMismatch" = ‘minItemsMismatch’; PATTERN_MISMATCH: "patternMismatch" = ‘patternMismatch’; RANGE_OVERFLOW: "rangeOverflow" = ‘rangeOverflow’; RANGE_UNDERFLOW: "rangeUnderflow" = ‘rangeUnderflow’; STEP_MISMATCH: "stepMismatch" = ‘stepMismatch’; TOO_LONG: "tooLong" = ‘tooLong’; TOO_SHORT: "tooShort" = ‘tooShort’; TYPE_MISMATCH: "typeMismatch" = ‘typeMismatch’; UNIQUE_ITEMS_MISMATCH: "uniqueItemsMismatch" = ‘uniqueItemsMismatch’; VALUE_MISSING: "valueMissing" = ‘valueMissing’ }>

ConstraintType is an object containing properties that represent the constraint types as per HTML5 specfication. Once can access these properties using dot notation (for example) (ConstraintType.PATTERN_MISMATCH, ConstraintType.TOO_SHORT, etc.).


FunctionRuntime

FunctionRuntime: FunctionRuntimeImpl


TRANSLATION_ID

TRANSLATION_ID: "afs:translationIds"

Name of the object which holds all translation specific properties


TRANSLATION_TOKEN

TRANSLATION_TOKEN: "##"

Token used while creating translation specific properties from adaptive form specification


constraintKeys

constraintKeys: Readonly<{ accept: "acceptMismatch" = ConstraintType.ACCEPT_MISMATCH; format: "formatMismatch" = ConstraintType.FORMAT_MISMATCH; maxFileSize: "fileSizeMismatch" = ConstraintType.FILE_SIZE_MISMATCH; maxItems: "maxItemsMismatch" = ConstraintType.MAX_ITEMS_MISMATCH; maxLength: "tooLong" = ConstraintType.TOO_LONG; maximum: "rangeOverflow" = ConstraintType.RANGE_OVERFLOW; minItems: "minItemsMismatch" = ConstraintType.MIN_ITEMS_MISMATCH; minLength: "tooShort" = ConstraintType.TOO_SHORT; minimum: "rangeUnderflow" = ConstraintType.RANGE_UNDERFLOW; pattern: "patternMismatch" = ConstraintType.PATTERN_MISMATCH; required: "valueMissing" = ConstraintType.VALUE_MISSING; step: "stepMismatch" = ConstraintType.STEP_MISMATCH; type: "typeMismatch" = ConstraintType.TYPE_MISMATCH; uniqueItems: "uniqueItemsMismatch" = ConstraintType.UNIQUE_ITEMS_MISMATCH; validationExpression: "expressionMismatch" = ConstraintType.EXPRESSION_MISMATCH }>

This map consists of key which are constraints based on `adaptive form specification and value which specifies constraint types as per HTML5 specification


constraintProps

constraintProps: string[]

Constant for all properties which are constraints based on adaptive form specification


translationProps

translationProps: string[]

Constant for all properties which can be translated based on adaptive form specification

Functions

checkIfConstraintsArePresent

Const checkIfConstraintsArePresent(item): boolean

Utility to check if the given form field has any data constraints

Parameters

Name Type Description
item FieldJson | FieldsetJson form field to check

Returns

boolean

true if item has data constraints, false otherwise


checkIfKeyAdded

checkIfKeyAdded(currentObj, prevObj, objKey): boolean

Checks if the key got added in current object

Parameters

Name Type
currentObj any
prevObj any
objKey string

Returns

boolean


createFormInstance

Const createFormInstance(formModel, callback?, logLevel?, fModel?): FormModel

Creates form instance using form model definition as per adaptive form specification

Parameters

Name Type Default value Description
formModel any undefined form model definition
callback? (f: FormModel) => any undefined a callback that recieves the FormModel instance that gets executed before any event in the Form is executed
logLevel LogLevel 'error' Logging Level for the form. Setting it off will disable the logging
fModel any undefined existing form model, this is additional optimization to prevent creation of form instance

Returns

FormModel

form model


createTranslationObject

Const createTranslationObject(input, additionalTranslationProps?, bcp47LangTags?): any

Creates translation object with BCP 47 language tags as key and value is a translation object. Key of translation object is generated based on the form hierarchy and it is separated by “##” token to signify that the id is machine generated (ie its not a human generated string)

Parameters

Name Type Default value Description
input any undefined form model definition
additionalTranslationProps string[] [] optional properties which needs to be translated, by default, only OOTB properties of form model definition is translated
bcp47LangTags string[] [] optional additional language tags

Returns

any

translation object for each bcp 47 language tag


defaultFieldTypes

Const defaultFieldTypes(schema): string

Returns the default view type for a given form field object based on adaptive form specification

Parameters

Name Type Description
schema any schema item for which default view type is to found

Returns

string

default view type


exportDataSchema

Const exportDataSchema(form): any

Creates a json schema from form model definition

Parameters

Name Type Description
form FormJson form model definition

Returns

any

json schema of form model definition


extractFileInfo

Const extractFileInfo(file): any

Utility to extract FileObject from string or HTML File data type

Parameters

Name Type
file any

Returns

any

list of FileObject


fetchForm

Const fetchForm(url, headers?): Promise<string>

Helper API to fetch form model definition from an AEM instance

Parameters

Name Type Description
url string URL of the instance
headers any HTTP headers to pass to the aem instance

Returns

Promise<string>

promise which resolves to the form model definition


getConstraintTypeMessages

Const getConstraintTypeMessages(): Object

API to get the constraint type messages

Returns

Object

Name Type
acceptMismatch "The specified file type not supported."
expressionMismatch "Please enter a valid value."
fileSizeMismatch "File too large. Reduce size and try again."
formatMismatch "Specify the value in allowed format : ${0}."
maxItemsMismatch "Specify a number of items equal to or less than ${0}."
minItemsMismatch "Specify a number of items equal to or greater than ${0}."
patternMismatch "Please match the format requested."
rangeOverflow "Value must be less than or equal to ${0}."
rangeUnderflow "Value must be greater than or equal to ${0}."
stepMismatch "Please enter a valid value."
tooLong "Please shorten this text to ${0} characters or less."
tooShort "Please lengthen this text to ${0} characters or more."
typeMismatch "Please enter a valid value."
uniqueItemsMismatch "All the items must be unique."
valueMissing "Please fill in this field."

getFileSizeInBytes

Const getFileSizeInBytes(str): number

Converts file size in string to bytes based on IEC specification

Parameters

Name Type Description
str any file size

Returns

number

file size as bytes (in kb) based on IEC specification


getOrElse

Const getOrElse(input, key, defaultValue?): any

Gets the value for the given key from the input, in case of no value, default is returned

Parameters

Name Type Default value Description
input any undefined input object
key string | string[] undefined key to return from input object (key could be comma separated, example, label.value)
defaultValue any null default value

Returns

any


getProperty

Const getProperty<P>(data, key, def): P

Get the property value form the json

Type parameters

Name Description
P type for the default value

Parameters

Name Type Description
data any object as json
key string name of the key
def P default value

Returns

P


isCaptcha

Const isCaptcha(item): boolean

Checks if the input item provided is a captcha field

Parameters

Name Type Description
item FieldJson | FieldsetJson input item it could be Fieldset or Field

Returns

boolean

true if item is a form captcha, false otherwise


isCheckbox

Const isCheckbox(item): boolean

Checks if the input item provided is a form check box field

Parameters

Name Type Description
item FieldJson | FieldsetJson input item it could be Fieldset or Field

Returns

boolean

true if item is a form check box, false otherwise


isCheckboxGroup

Const isCheckboxGroup(item): boolean

Checks if the input item provided is a form check box group field

Parameters

Name Type Description
item FieldJson | FieldsetJson input item it could be Fieldset or Field

Returns

boolean

true if item is a form check box group, false otherwise


isDateField

Const isDateField(item): boolean

Checks if the input item provided is a date field

Parameters

Name Type Description
item FieldJson | FieldsetJson input item it could be Fieldset or Field

Returns

boolean

true if item is a form check box group, false otherwise


isEmailInput

Const isEmailInput(item): boolean

Checks if the input item provided is a form check box group field

Parameters

Name Type Description
item FieldJson | FieldsetJson input item it could be Fieldset or Field

Returns

boolean

true if item is a form check box group, false otherwise


isEmpty

Const isEmpty(value): boolean

Utility to check if the value is empty

Parameters

Name Type Description
value any value

Returns

boolean

true if value is empty, false otherwise


isFile

Const isFile(item): boolean

Checks if the input item provided is a form file attachment field

Parameters

Name Type Description
item FieldJson | FieldsetJson input item it could be Fieldset or Field

Returns

boolean

true if item is a form file attachment, false otherwise


isRepeatable

Const isRepeatable(obj): boolean

Parameters

Name Type
obj FieldJson | FieldsetJson

Returns

boolean


jsonString

Const jsonString(obj): string

Prettifies obj as json string

Parameters

Name Type Description
obj any object to prettify

Returns

string

json string


propertyChange

Const propertyChange(propertyName, currentValue, prevValue?): Change

Creates a change event

Parameters

Name Type Description
propertyName string name of the form field property
currentValue any current value
prevValue? any previous value

Returns

Change

Change change event


registerFunctions

Const registerFunctions(functions): void

Parameters

Name Type
functions Object

Returns

void


restoreFormInstance

Const restoreFormInstance(formModel, data?, __namedParameters?): FormModel

Parameters

Name Type Default value
formModel any undefined
data any null
__namedParameters Object defaultOptions
__namedParameters.logLevel LogLevel undefined

Returns

FormModel


setCustomDefaultConstraintTypeMessages

Const setCustomDefaultConstraintTypeMessages(messages): void

API to override the custom default constraint messages

Parameters

Name Type Description
messages Record<string, string> messages to override as per {@link defaultConstraintTypeMessages} As an example, // Example usage: setCustomConstraintMessages({ 'pattern': 'Custom pattern mismatch message.', 'minLength': 'Custom too short message.', });

Returns

void


validateFormData

Const validateFormData(formModel, data): Object

Validates Form model definition with the given data

Parameters

Name Type Description
formModel any form model definition
data any form data

Returns

Object

Name Type
messages any[]
valid boolean

validateFormInstance

Const validateFormInstance(formModel, data): boolean

Validates Form model definition with the given data

deprecated use validateFormData

Parameters

Name Type Description
formModel any form model definition
data any form data

Returns

boolean

true, if form is valid against the given form data, false otherwise