Perspective - Form Scripting
This page details the various scripting, component, and extension functions available for Perspective's Form component. Scripting allows you to customize form behavior, handle validation dynamically, and respond to user actions.
Component Eventsβ
The Perspective Event Types Reference page describes all possible event types for Perspective components. Not all event types apply to every component. For more information on configuring events, see Component Events and Actions.
onChangeβ
This event triggers whenever a form's input value changes.
Propertiesβ
| Property | Type | Description |
|---|---|---|
| event.inputKey | String | The unique key identifying the input that triggered the change. |
| event.newValue | Object | The new value of the input after the change. |
| event.oldValue | Object | The previous value of the input before the change occurred. |
| event.index | Integer | The index of the input if multiple inputs share the same key, such as in a repeater or table. Optional. |
onSuccessβ
This event triggers when a form submission completes successfully.
Propertiesβ
| Property | Type | Description |
|---|---|---|
| event | Object | The success response object returned after submission. |
See Form Submission for handling form data on submission.
onErrorβ
This event triggers when a form submission fails.
Propertiesβ
| Property | Type | Description |
|---|---|---|
| event | Object | The error response object returned from the submission. |
See Form Submission for handling errors.
onCancelActionPerformedβ
If configured, this component event fires when the Form's cancel action is clicked.
Propertiesβ
| Property | Type | Description |
|---|---|---|
| event | Object | A JSON object containing all form input data to be cancelled. |
onSubmitActionPerformedβ
If configured, this component event fires when the Form's submit action is clicked.
Propertiesβ
| Property | Type | Description |
|---|---|---|
| event | Object | A JSON object containing all form input data to be submitted. |
Component Functionsβ
.setCustomValidity(message, inputKey, index)β
Descriptionβ
Sets a custom validation message for a specific input field in the form.
Parametersβ
| Parameter | Type | Description |
|---|---|---|
| message | String | The custom validation message to display for this input. |
| inputKey | String | The unique key identifying the input field. |
| index | Integer | The index of the input if multiple inputs share the same key. Optional. |
Returnβ
None
Exampleβ
To set a custom validation message for an email input field:
self.getSibling("Form").setCustomValidity("Please provide a valid email address.", "email")
This message will persist until the field is corrected or the form is reset.
.reset()β
Descriptionβ
Resets all form inputs to their default values.
Parametersβ
None
Returnβ
None
Exampleβ
To reset the form inputs to their default state:
self.getSibling("Form").reset()
.submit(preventInvalid)β
Descriptionβ
Submits the form, triggering onSuccess if successful or onError if submission fails.
Parametersβ
| Parameter | Type | Description |
|---|---|---|
| preventInvalid | Boolean | When true, prevents the form from submitting if it is invalid. Optional. |
Returnβ
None
Exampleβ
To submit the form with validation check enabled:
self.getSibling("Form").submit(preventInvalid=True)
Extension Functionsβ
This component does not have any extension functions associated with it.