Home Reference Source
import FormController from '~/controllers/Form/FormController.js'
public class | source

FormController

Extends:

js/controllers/controllers/ViewController.js~ViewController → FormController

Performs really basic form validation

Constructor Summary

Public Constructor
public

constructor(form: HTMLFormElement)

Sets up an empty form validation for a form.

Member Summary

Public Members
public
public get

formData: FormData

Returns form data.

public get

Returns HTTP method

public get

Returns action target.

public get

Prepares a AJAX request with form endpoints

Method Summary

Public Methods
public

Adds a form constraint

public

addConstraints(constraints: FormConstraint[])

Adds a list of constraints.

public

Hides error displays

public

Displays the errors.

public

Returns a foreign synchronization node

public

setFieldWithName(value: string, name: string)

Creates or sets a form field with a name as an identifying key.

public

Submits a form.

public

Validates the form.

Public Constructors

public constructor(form: HTMLFormElement) source

Sets up an empty form validation for a form. This will run when the form is submitted, or manually using the .submit() function. Setup a delegate too

Params:

NameTypeAttributeDescription
form HTMLFormElement

Form element

Public Members

public delegate: FormControllerDelegate source

public get formData: FormData source

Returns form data.

public get method: string source

Returns HTTP method

public get path: string source

Returns action target.

public get request: Request source

Prepares a AJAX request with form endpoints

Public Methods

public addConstraint(constraint: FormConstraint) source

Adds a form constraint

Params:

NameTypeAttributeDescription
constraint FormConstraint

A constraint to add to the current form.

public addConstraints(constraints: FormConstraint[]) source

Adds a list of constraints.

Params:

NameTypeAttributeDescription
constraints FormConstraint[]

A list of form constraints to add

public clearDisplays() source

Hides error displays

public display(errors: ValidationError[]) source

Displays the errors.

Params:

NameTypeAttributeDescription
errors ValidationError[]

List of validation errors.

public foreignSynchronize(text: string, time: number) source

Returns a foreign synchronization node

Params:

NameTypeAttributeDescription
text string

Name of the syncronization node

time number
  • optional
  • default: 50

Minimum time before resyncronization

public setFieldWithName(value: string, name: string) source

Creates or sets a form field with a name as an identifying key.

Params:

NameTypeAttributeDescription
value string

Value of the new field.

name string

name identifying field

public submit(): boolean source

Submits a form.

Return:

boolean

true if succesful, false otherwise.

public validate(): ValidationError[] source

Validates the form.

Return:

ValidationError[]

List of errors