FormsApi

This class provides properties and methods for communicating with a form.

Members

baseUrl :string

Get the Lime Forms installation base url.
Type:
  • string

currentStep :Step

The name and index of the current step.
Type:
  • Step

formData :Object

Get the form data.
Type:
  • Object

http :object

This property holds an instance of axios (https://github.com/axios/axios) that you may use to perform http requests.
Type:
  • object

locale :string

Get the form locale.
Type:
  • string

stepCount :number

The number of steps in the form.
Type:
  • number

steps :array.<Step>

The name and index of each step in the form.
Type:
  • array.<Step>

version :number

Get the Lime Forms version.
Type:
  • number

Methods

excludeField(fieldName)

Set field to be excluded (hide and exclude from submission). If a field name is identical in multiple steps, you may pass fieldName@stepIndex as fieldName to target the correct field. See excludeField.
Parameters:
Name Type Description
fieldName string

getFieldValue(fieldName, onlyIncludedFields) → {string|number}

Get the current value of a field by name. If a field name is identical in multiple steps, you may pass fieldName@stepIndex as fieldName to target the correct field. See getFieldValue.
Parameters:
Name Type Default Description
fieldName string
onlyIncludedFields boolean false Whether to only get the fields that are currently set to be included in the submission
Returns:
Type
string | number

getFieldValues(fieldNames, onlyIncludedFields) → {object}

Get the current values of multiple fields at the same time. If a field name is identical in multiple steps, you may pass fieldName@stepIndex as fieldName to target the correct field. See getFieldValue.
Parameters:
Name Type Default Description
fieldNames array
onlyIncludedFields boolean false Whether to only get the fields that are currently set to being included in the submission or not
Returns:
Returns an object with each field name and current value mapped as key-value pairs.
Type
object

goToNextStep(settings)

Go to the next step. See Navigation.
Parameters:
Name Type Description
settings object
Properties
Name Type Attributes Default Description
skipValidation boolean <optional>
false Whether to skip validation of the active step before navigating or not.

goToPrevStep()

Go to the previous step. See Navigation.

includeField(fieldName)

Set field to be included (show and include in submission). If a field name is identical in multiple steps, you may pass fieldName@stepIndex as fieldName to target the correct field. See includeField.
Parameters:
Name Type Description
fieldName string

onBeforeNextStep(callback)

Attach a callback function to execute before navigating to the next step. If the callback returns a Promise, the step will wait for it to be resolved before navigating. See Navigation.
Parameters:
Name Type Description
callback beforeNextStepCallback

onBeforeSubmit(callback)

Attach a callback function to execute before the form submission is sent to the backend. If the callback returns a Promise, the form will wait for it to be resolved before submitting. See Submitting.
Parameters:
Name Type Description
callback function

onEval(callback)

Attach a callback to execute when conditionals are being evaluated. See onEval.
Parameters:
Name Type Description
callback function

onFieldValueChange(fieldName, callback)

Attach a callback to execute when given field value has changed. If a field name is identical in multiple steps, you may pass fieldName@stepIndex as fieldName to target the correct field. See onFieldValueChange.
Parameters:
Name Type Description
fieldName string
callback fieldValueChangeCallback

onNextStep(callback)

Attach a callback function to execute when navigating to the next step. See Navigation.
Parameters:
Name Type Description
callback stepChangeCallback

onPrevStep(callback)

Attach a callback function to execute when navigating to the previous step. See Navigation.
Parameters:
Name Type Description
callback stepChangeCallback

onReady(callback)

Attach a callback function to execute when the form is initialized and ready. The callback will be excecuted with 'this' bound to the formsApi instance.
Parameters:
Name Type Description
callback function

onStepChange(callback)

Attach a callback function to execute every time navigation occurs. See Navigation.
Parameters:
Name Type Description
callback stepChangeCallback

onSubmitted(callback)

Attach a callback function to execute when the form has been submitted successfully. See Submitting.
Parameters:
Name Type Description
callback function

setFieldValue(fieldName, value)

Set the value of a field. If a field name is identical in multiple steps, you may pass fieldName@stepIndex as fieldName to target the correct field. See setFieldValue.
Parameters:
Name Type Description
fieldName string
value string | number

setFieldValues(valueObj)

Set multiple field values at the same time. If a field name is identical in multiple steps, you may pass fieldName@stepIndex as fieldName to target the correct field. See setFieldValue.
Parameters:
Name Type Description
valueObj object An object with each field name and value to set as key-value pairs.

submit()

Submit the form.

Type Definitions

beforeNextStepCallback(from, to, prevBtn, nextBtn)

Callback for before next step.
Parameters:
Name Type Description
from Step The current step
to Step The being navigated to
prevBtn HTMLElement The previous button element (provided for setting loading state etc.)
nextBtn HTMLElement The next button element (provided for setting loading state etc.)

fieldValueChangeCallback(value)

Callback field value change.
Parameters:
Name Type Description
value string | array | number The changed field value

Step

Properties:
Name Type Description
name string The name of the step
index number The index of the step
Type:
  • object

stepChangeCallback(from, to)

Callback for step change.
Parameters:
Name Type Description
from Step The current step
to Step The being navigated to