Interface: FormController<T>
forms/types/FormController.FormController
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.
Type parameters
Name |
---|
T |
Hierarchy
↳ FormController
Properties
addFields
• addFields: (fieldSpec
: Partial
<FieldSetOptions
<T
>>) => void
Type declaration
▸ (fieldSpec
): void
Adds fields to the form
Parameters
Name | Type | Description |
---|---|---|
fieldSpec |
Partial <FieldSetOptions <T >> |
FieldSetOptions with defined fields to add. |
Returns
void
Defined in
src/base/forms/types/FormController.ts:62
attr
• attr: attrName
: Key
) => FormState
<T
>[Key
]
Type declaration
▸ <Key
>(attrName
): FormState
<T
>[Key
]
Retrieves a particular attribute from the state for this module.
Type parameters
Name | Type |
---|---|
Key |
extends "errors" | "fields" | "disabled" | "step" | "name" | "endpoint" | "method" | "sending" | "persistent" |
Parameters
Name | Type |
---|---|
attrName |
Key |
Returns
FormState
<T
>[Key
]
Inherited from
Defined in
src/base/types/BaseController.ts:40
clearErrors
• clearErrors: () => void
Type declaration
▸ (): void
Clears all error-related settings on the form and its fields.
Returns
void
Defined in
src/base/forms/types/FormController.ts:112
commit
• commit: <OutsideModuleDefinition, Key>(funcName
: Key
| `${string}/${Key}`, ...payload
: ParametersExceptFirst
<OutsideModuleDefinition
["mutations"
][Key
]>) => void
Type declaration
▸ <OutsideModuleDefinition
, Key
>(funcName
, ...payload
): void
Commits a mutation for this module.
Type parameters
Name | Type |
---|---|
OutsideModuleDefinition |
extends BaseModule <any , any , any > = BaseFormModule <T > |
Key |
extends string = string & keyof OutsideModuleDefinition ["mutations" ] |
Parameters
Name | Type |
---|---|
funcName |
Key | `${string}/${Key}` |
...payload |
ParametersExceptFirst <OutsideModuleDefinition ["mutations" ][Key ]> |
Returns
void
Inherited from
Defined in
src/base/types/BaseController.ts:44
data
• data: T
Derives the data from the form for submission. Creates an instance of T
, omitting fields that match their
OmitIf
value.
Defined in
src/base/forms/types/FormController.ts:80
delFields
• delFields: (names
: keyof T
[]) => void
Type declaration
▸ (names
): void
Deletes fields from the form.
Parameters
Name | Type | Description |
---|---|---|
names |
keyof T [] |
Field names to remove. |
Returns
void
Defined in
src/base/forms/types/FormController.ts:57
dispatch
• dispatch: <Key>(funcName
: Key
, ...payload
: ParametersExceptFirst
<FormTasks
<T
, BaseFormModule
<T
>>[Key
]>) => ReturnType
<FormTasks
<T
, BaseFormModule
<T
>>[Key
]> | <Key>(funcName
: Key
, ...payload
: ParametersExceptFirst
<FormTasks
<T
, BaseFormModule
<T
>>[Key
]>) => ReturnType
<FormTasks
<T
, BaseFormModule
<T
>>[Key
]>
Dispatches a task for this module.
Inherited from
Defined in
src/base/types/BaseController.ts:48
endpoint
• endpoint: string
The endpoint property on the form module. This is a getter/setter, so you can update the endpoint.
Defined in
src/base/forms/types/FormController.ts:17
errors
• errors: string
[]
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.
Defined in
src/base/forms/types/FormController.ts:71
f
• f: BoundFielders
<T
>
Fielders.
Defined in
src/base/forms/types/FormController.ts:26
getFieldSetting
• getFieldSetting: name
: FieldName
, settingName
: SettingName
) => FieldSet
<T
>[FieldName
][SettingName
]
Type declaration
▸ <FieldName
, SettingName
>(name
, settingName
): FieldSet
<T
>[FieldName
][SettingName
]
Gets a particular setting on a specific field from the form module.
Type parameters
Name | Type |
---|---|
FieldName |
extends string | number | symbol |
SettingName |
extends string | number | symbol |
Parameters
Name | Type | Description |
---|---|---|
name |
FieldName |
The name of the field |
settingName |
SettingName |
The name of the setting on the field. |
Returns
FieldSet
<T
>[FieldName
][SettingName
]
Defined in
src/base/forms/types/FormController.ts:40
handleError
• handleError: (error
: AxiosError
<unknown
, any
>) => void
Type declaration
▸ (error
): void
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
controller.submit().then(yourSuccessFunction, controller.handleError)
Parameters
Name | Type | Description |
---|---|---|
error |
AxiosError <unknown , any > |
An AxiosError raised when submitting the form. |
Returns
void
Defined in
src/base/forms/types/FormController.ts:103
hasField
• hasField: (fieldName
: string
) => boolean
Type declaration
▸ (fieldName
): boolean
Returns true if the form has a field by a particular name.
Parameters
Name | Type |
---|---|
fieldName |
string |
Returns
boolean
Defined in
src/base/forms/types/FormController.ts:34
managedNames
• managedNames: string
[]
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
Defined in
src/base/types/BaseController.ts:36
method
• method: Method
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.
Defined in
src/base/forms/types/FormController.ts:22
moduleType
• moduleType: "form"
Returns 'form
', the type of module this controller handles.
Defined in
src/base/forms/types/FormController.ts:13
name
• name: string
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
Defined in
src/base/types/BaseController.ts:21
namespace
• namespace: string
[]
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
Defined in
src/base/types/BaseController.ts:31
preDestroy
• preDestroy: () => void
Type declaration
▸ (): void
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
Defined in
src/base/types/BaseController.ts:53
rawState
• rawState: FormState
<T
>
The raw state of the dynamically created module. This should be a copy so mutating the output doesn't affect the state.
Inherited from
Defined in
src/base/types/BaseController.ts:26
reset
• reset: () => void
Type declaration
▸ (): void
Resets the form to its default state-- including all fields at their initial values and clearing all errors.
Returns
void
Defined in
src/base/forms/types/FormController.ts:116
sending
• sending: boolean
Returns whether the form is currently being submitted.
Defined in
src/base/forms/types/FormController.ts:30
setErrors
• setErrors: (errorSet
: FormErrorSet
<any
>) => void
Type declaration
▸ (errorSet
): void
Sets the form's error state from a FormErrorSet
.
Parameters
Name | Type | Description |
---|---|---|
errorSet |
FormErrorSet <any > |
A FormErrorSet containing errors for this form. |
Returns
void
Defined in
src/base/forms/types/FormController.ts:91
setFieldSetting
• setFieldSetting: <FieldName, SettingName>(name
: FieldName
, settingName
: SettingName
, value
: FieldSet
<T
>[FieldName
][SettingName
]) => void
Type declaration
▸ <FieldName
, SettingName
>(name
, settingName
, value
): void
Sets a particular setting on a specific field from the form module.
Type parameters
Name | Type |
---|---|
FieldName |
extends string | number | symbol |
SettingName |
extends string | number | symbol |
Parameters
Name | Type | Description |
---|---|---|
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
Defined in
src/base/forms/types/FormController.ts:50
status
• status: string
Gets/sets The status code of the last failed submit request.
Defined in
src/base/forms/types/FormController.ts:75
step
• step: number
Gets/sets which 'Step' the form is on. This is used to break up long forms into multi-step wizards.
Defined in
src/base/forms/types/FormController.ts:66
stopValidators
• stopValidators: () => void
Type declaration
▸ (): void
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
Defined in
src/base/forms/types/FormController.ts:108
submit
• submit: Promise
<K
>
Type declaration
▸ <K
>(): Promise
<K
>
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
Name |
---|
K |
Returns
Promise
<K
>
Defined in
src/base/forms/types/FormController.ts:85
uid
• Private
uid: string
An internal ID used to track this controller as a listener of single modules.