BackgroundBehavior Model

The Model behavior connects a component to a parent Form.It also sets up a two way binding to the path inside the local scopethat is defined in the attribute's value.

Native form elements are working with form validation out of the box.

For custom components that should hook into the form validation yourimplementation must set the value property of the component instanceevery time the model's value should change. Of course a change in themodel's value will update the value property.

Example

<input name="username" type="text" model="username"/><input name="email" type="email" model="email"/><input name="birthday" type="date" model="birthday"/><input name="rating" type="number" model="rating"/><select name="suggestion" model="suggestion">    <option>Yes</option>    <option>No</option></select>
alias

{ default } from mahalo/behaviors/model

Hierarchy

Index

Constructors

constructor

  • new Model(path: string): Model

Properties

component

component:Component

The component the behavior belongs to.

controller

The controller of the behavior's component.

element

element:Element

The element the behavior was attached to.

form

form:Form

The form that the model belongs to.

name

name:string

The field name that is used in the form.

path

path:string

The key path to the model's value.

skip

skip:boolean

A flag that indicates that a change to the modelwas triggered internally.

Static update

update:string = "update"

Methods

Private initElement

  • initElement(value: any): any
  • Initializes native form elements by addingrequired validators.

    Parameters
    • value: any
    Returns any

remove

  • remove(): void
  • Returns void

update

  • update(value: any): void
  • Updates the value property of the componentwhenever the modal has changed.

    Parameters
    • value: any
    Returns void

updateModel

  • updateModel(value: any): void
  • Updates the model's value whenever the property ofthe component has changed.

    Parameters
    • value: any
    Returns void

Object literals

Static bindings

bindings:object

component.value

component.value:string = "updateModel"

Static inject

inject:object

component

component:Component = Component

controller

controller:ComponentController = ComponentController

element

element:Element = Element

form

form:Form = Form