Skip to content

@opencraft/providence


Interface: FormController\<T>

Defined in: forms/types/FormController.ts:9

Controllers are the public interface for interacting with providence modules in your store of choice. There will only ever be one controller per registered module, thanks to the registry. The controller should not hold information that can't be reconstructed upon hot reload. It should merely be an interface for manipulating the registered module.

Extends

Type Parameters

T

T

Properties

addFields

addFields: (fieldSpec) => void

Defined in: forms/types/FormController.ts:62

Adds fields to the form

Parameters

fieldSpec

Partial\<FieldSetOptions\<T>>

FieldSetOptions with defined fields to add.

Returns

void


attr

attr: \<Key>(attrName) => FormState\<T>[Key]

Defined in: types/BaseController.ts:40

Retrieves a particular attribute from the state for this module.

Type Parameters

Key

Key extends "errors" | "fields" | "disabled" | "step" | "name" | "endpoint" | "method" | "sending" | "persistent"

Parameters

attrName

Key

Returns

FormState\<T>[Key]

Inherited from

BaseController.attr


clearErrors

clearErrors: () => void

Defined in: forms/types/FormController.ts:112

Clears all error-related settings on the form and its fields.

Returns

void


commit

commit: \<OutsideModuleDefinition, Key>(funcName, ...payload) => void

Defined in: types/BaseController.ts:44

Commits a mutation for this module.

Type Parameters

OutsideModuleDefinition

OutsideModuleDefinition extends BaseModule\<any, any, any> = BaseFormModule\<T>

Key

Key extends string = string & keyof OutsideModuleDefinition["mutations"]

Parameters

funcName

Key | `${string}/${Key}`

payload

...ParametersExceptFirst\<OutsideModuleDefinition["mutations"][Key]>

Returns

void

Inherited from

BaseController.commit


data

data: T

Defined in: forms/types/FormController.ts:80

Derives the data from the form for submission. Creates an instance of T, omitting fields that match their OmitIf value.


delFields

delFields: (names) => void

Defined in: forms/types/FormController.ts:57

Deletes fields from the form.

Parameters

names

keyof T[]

Field names to remove.

Returns

void


dispatch

dispatch: (\<Key>(funcName, ...payload) => ReturnType\<FormTasks\<T, BaseFormModule\<T>>[Key]>) | (\<Key>(funcName, ...payload) => ReturnType\<FormTasks\<T, BaseFormModule\<T>>[Key]>)

Defined in: types/BaseController.ts:48

Dispatches a task for this module.

Inherited from

BaseController.dispatch


endpoint

endpoint: string

Defined in: forms/types/FormController.ts:17

The endpoint property on the form module. This is a getter/setter, so you can update the endpoint.


errors

errors: string[]

Defined in: forms/types/FormController.ts:71

Form-level errors. These are errors returned by the server which do not apply to any specific field. To get field-level errors, use the Fielders.


f

f: BoundFielders\<T>

Defined in: forms/types/FormController.ts:26

Fielders.


getFieldSetting

getFieldSetting: \<FieldName, SettingName>(name, settingName) => FieldSet\<T>[FieldName][SettingName]

Defined in: forms/types/FormController.ts:40

Gets a particular setting on a specific field from the form module.

Type Parameters

FieldName

FieldName extends string | number | symbol

SettingName

SettingName extends string | number | symbol

Parameters

name

FieldName

The name of the field

settingName

SettingName

The name of the setting on the field.

Returns

FieldSet\<T>[FieldName][SettingName]


handleError

handleError: (error) => void

Defined in: forms/types/FormController.ts:103

A provided helper function which handles most of the cleanup when there's an error from submitting a form. Derives the errors, and adjusts the state to show them and move the form step to the first error in the set. Use this as the error handler for the submit function, like so:

.. code-block:: typescript

Text Only
controller.submit().then(yourSuccessFunction, controller.handleError)

Parameters

error

AxiosError

An AxiosError raised when submitting the form.

Returns

void


hasField

hasField: (fieldName) => boolean

Defined in: forms/types/FormController.ts:34

Returns true if the form has a field by a particular name.

Parameters

fieldName

string

Returns

boolean


managedNames

managedNames: string[]

Defined in: types/BaseController.ts:36

Returns the names of all modules this module manages. For singles, that will only be the current module name. For lists, it will be the current module name and all the names of the singles it manages.

Inherited from

BaseController.managedNames


method

method: Method

Defined in: forms/types/FormController.ts:22

The HTTP method used when submitting this form. Usually this is 'post' or 'put'. This is a getter/setter, in case you need to update it for some reason.


moduleType

moduleType: "form"

Defined in: forms/types/FormController.ts:13

Returns 'form', the type of module this controller handles.


name

name: string

Defined in: types/BaseController.ts:21

The name of the dynamically created module. This is a dot separated name. You can construct an escaped, valid name with use of the flattenNamespace function.

Inherited from

BaseController.name


namespace

namespace: string[]

Defined in: types/BaseController.ts:31

Useful for when needing to walk through modules for an operation, namespace returns an array of strings representing this module's location in the hierarchy.

Inherited from

BaseController.namespace


preDestroy

preDestroy: () => void

Defined in: types/BaseController.ts:53

A function which is run after the controller is no longer needed (because all listeners have disconnected), before it is removed from the store.

Returns

void

Inherited from

BaseController.preDestroy


rawState

rawState: FormState\<T>

Defined in: types/BaseController.ts:26

The raw state of the dynamically created module. This should be a copy so mutating the output doesn't affect the state.

Inherited from

BaseController.rawState


reset

reset: () => void

Defined in: forms/types/FormController.ts:116

Resets the form to its default state-- including all fields at their initial values and clearing all errors.

Returns

void


sending

sending: boolean

Defined in: forms/types/FormController.ts:30

Returns whether the form is currently being submitted.


setErrors

setErrors: (errorSet) => void

Defined in: forms/types/FormController.ts:91

Sets the form's error state from a FormErrorSet.

Parameters

errorSet

FormErrorSet

A FormErrorSet containing errors for this form.

Returns

void


setFieldSetting

setFieldSetting: \<FieldName, SettingName>(name, settingName, value) => void

Defined in: forms/types/FormController.ts:50

Sets a particular setting on a specific field from the form module.

Type Parameters

FieldName

FieldName extends string | number | symbol

SettingName

SettingName extends string | number | symbol

Parameters

name

FieldName

The name of the field

settingName

SettingName

The name of the setting on the field.

value

FieldSet\<T>[FieldName][SettingName]

The value to set.

Returns

void


status

status: string

Defined in: forms/types/FormController.ts:75

Gets/sets The status code of the last failed submit request.


step

step: number

Defined in: forms/types/FormController.ts:66

Gets/sets which 'Step' the form is on. This is used to break up long forms into multi-step wizards.


stopValidators

stopValidators: () => void

Defined in: forms/types/FormController.ts:108

Stops all validation currently in progress for form fields. Useful when you're about to set errors manually but they might be overwritten by in-progress validation.

Returns

void


submit

submit: \<K>() => Promise\<K>

Defined in: forms/types/FormController.ts:85

Submits the form, returning a promise from the submission. It is recommended to catch any errors from this submission with the handleError function.

Type Parameters

K

K

Returns

Promise\<K>