BackgroundComponent Form

The Form component provides simple validation forform field components.

alias

{ default } from mahalo/components/form

Hierarchy

Index

Constructors

constructor

Properties

$dirty

$dirty:boolean = false

A flag that indicated if the form has been changed.

$fields

$fields:object

A map of fields used in this form.

$valid

$valid:boolean = true

A flag that indicates if the form is currently valid.

element

element:Element

submit

submit:EventListener

An interceptor for the submit event that prevents invalidforms from beeing submited.

Static attributes

attributes:object

A map containing keys of properties that will pull in their value froma given attribute of the defining element. The values are strings thatdescribe the binding that will be created as well as the attribute name.In case you want the attribute's value to be treated as an expression youcan use one of the following symbols as a first character:

  • '?': Will compile the expression once an set the property's value to the result.
  • '.': Will update the property's value to the result of the expression whenever it changes.
  • ':': Will keep the property's value in sync with the value at the path given in the attribute's value.

If one of these characters is found they will be trimmed from the string.If the string is not empty after that it will be used as the name of attribute.Otherwise the attribute's name is assumed to be equal to a hyphenated versionof the property name.

Example
export default class MyComponent extends Component {    static attributes = {        // <my-component use-as-is=""></my-component>        useAsIs: '',        // <my-component compile-once="myVar + 1"></my-component>        compileOnce: '?',        // <my-component bind-one-way="myVar + 10"></my-component>        bindOneWay: '.',        // <my-component my-attribute="myVar"></my-component>        bindTwoWayAndDefineName: ':my-attribute'    };}

Static bindings

bindings:object

This static property lets you define listeners that will be executed whenproperties of the component change.

It should be a map where the keys are paths that should be watched on the component andthe values are names of methods that will be invoked on the component instance.

Example

In the following example you can see a component that reacts to changesin the size of the defining element.

export default class MyComponent extends Component {    static inject: {element: Element};    static bindings = {        'element.clientHeight': 'heightChange'    };    width: number;    heightChange(height: number) {        this.width = height * 2;    }}

Static locals

locals:Array<string> = ['$fields', '$valid', '$dirty']

Static template

template:string | Template

When a string is given it must contain the html of the component's template.

In general you should not make use of this at all. Your template should bein a separate file with the same name and in the same folder as your component'sTypeScript file. This feature is only for advanced usage (for example having an emptytemplate by setting this to an empty string) or rapid prototyping.

Methods

enter

  • enter(): void
  • Returns void

leave

  • leave(): void
  • Returns void

ready

  • ready(): void
  • Returns void

remove

  • remove(): void

setValue

  • setValue(name: string, value: any): boolean
  • Updates the value of field.

    Parameters
    • name: string
    • value: any
    Returns boolean

Private validateField

  • validateField(name: string, value: any): boolean
  • Parameters
    • name: string
    • value: any
    Returns boolean

Private validateForm

  • validateForm(): void
  • Returns void

Object literals

Static inject

inject:object

element

element:Element = Element