Class: Field

Field

Abstract class that served as base for all Alpaca field classes that provide actual implementation.


new Field(domEl, data, options, schema, viewId, connector, errorCallback)

Parameters:
Name Type Description
domEl Object

The dom element to which this field is ultimately rendering.

data Any

Field data

options Object

Field options.

schema Object

Field schema.

viewId String

view id

connector Alpaca.Connector

Field connector.

errorCallback function

Error callback.

Source:

Methods


<private> _processRender(parentEl, callback)

Renders the field into the given parent element.

Once completed, the callback method is called.

Parameters:
Name Type Description
parentEl Object

Field container.

callback function

callback.

Source:

<private> _render(callback)

Internal method for processing the render.

Parameters:
Name Type Description
callback function

Post-render callback.

Source:

_validateCustomValidator()

Validates using user provided validator.

Source:

_validateDisallow()

Checks whether the field value is allowed or not.

Source:
Returns:

True if the field value is allowed, false otherwise.

Type
Boolean

_validateOptional()

Validates against required property.

Source:
Returns:

False if this field value is empty but required, true otherwise.

Type
Boolean

applyStyle(id, target)

Applies a view style to a dom element.

Parameters:
Name Type Description
id
target
Source:

bindData()

Binds the data into the field. Called at the very end of construction.

Source:

clear()

Clears the field and resets the field to its original value.

Source:

destroy()

Purges any event listeners and remove this field from the DOM.

Source:

disable()

Source:

displayMessage(messages, beforeStatus)

Sets the validation state messages to show for a given field.

Parameters:
Name Type Description
messages Object | Array

either a message object {id, message} or an array of message objects

beforeStatus Boolean

Previous validation status.

Source:

enable()

Enables the field.

Source:

fireCallback(id, arg1, arg2, arg3, arg4, arg5)

Fires a view callback for the current field.

Parameters:
Name Type Description
id
arg1
arg2
arg3
arg4
arg5
Source:

focus()

Focuses on the field.

If a callback is provided, the callback receives the control focused upon.

Source:

getBaseFieldType()

Source:
Returns:

the type of the base class (or null if none)

Type
String

getControlByPath(path)

Finds a field control by its path.

Parameters:
Name Type Description
path String

Field control path.

Source:
Returns:

Field control mapped to the path.

Type
Alpaca.Field

getControlsByFieldType(fieldType)

Retrieves an array of Alpaca controls by their Alpaca field type (i.e. "text", "checkbox", "ckeditor")
This does a deep traversal across the graph of Alpaca field instances.

Parameters:
Name Type Description
fieldType
Source:
Returns:
Type
Array

getControlsBySchemaType(schemaType)

Retrieves an array of Alpaca controls by their schema type (i.e. "string", "number").
This does a deep traversal across the graph of Alpaca field instances.

Parameters:
Name Type Description
schemaType
Source:
Returns:
Type
Array

getDescription()

Returns field description.

Source:
Returns:

Field description.

Type
String

getFieldEl()

Retrieves the outer "field" rendered DOM element.

If this field is a control field or a container field, this DOM element will wrap the inner "control"
and "container" elements respectively. In some cases, the wrapping might not exist in which case this
field may be the "control" or "container" field itself.

Source:
Returns:

The rendered DOM element.

Type
Object

getFieldType()

Returns a string that identifies the type of field.

Source:
Returns:
Type
string

getId()

Returns the id of the field.

Source:
Returns:

Field id.


getMessage(key)

View and locale friendly retrieval of messages.

Parameters:
Name Type Description
key
Source:

getName()

Retrieves the name of this element at the current level of JSON data.

Source:
Returns:
Type
*

<private> getOptionsForOptions()

Returns Alpaca options for the Alpaca options that are managed by this class.

Source:
Returns:

Alpaca options for the Alpaca options that are managed by this class.

Type
Object

<private> getOptionsForSchema()

Returns Alpaca options for the schema properties that managed by this class.

Source:
Returns:

Alpaca options for the schema properties that are managed by this class.

Type
Object

getParent()

Returns this field's parent.

Source:
Returns:

Field parent.

Type
Alpaca.Field

getPath()

Retrieves the path to this element in the graph of JSON data.

Source:
Returns:

the path to this element

Type
string

<private> getSchemaOfOptions()

Returns JSON schema of the Alpaca options that are managed by this class.

Source:
Returns:

JSON schema of the Alpaca options that are managed by this class.

Type
Object

<private> getSchemaOfSchema()

Returns JSON schema of the schema properties that are managed by this class.

Source:
Returns:

JSON schema of the schema properties that are managed by this class.

Type
Object

getTemplateDescriptor()

Returns the field template descriptor.

Source:
Returns:

template descriptor

Type
Object

getTemplateDescriptorId()

Get the id of the outer field template.

For control fields, this is "control".
For container fields, this is "container".

Source:
Returns:

field template descriptor id

Type
String

getTitle()

Returns field title.

Source:
Returns:

Field title.

Type
String

getType()

Returns schema data type.

Source:
Returns:

Schema data type.

Type
String

getValue()

Returns the value of this field.

Source:
Returns:

value Field value.

Type
Any

handleValidate()

Performs validation.

Source:

hide()

Hides the field.

Source:

initEvents()

Initializes event handling.

Source:

initTemplateDescriptor()

Sets up default rendition template from view.

Source:

isContainer()

Finds if this field is a container of other fields.

Source:
Returns:

True if it is a container, false otherwise.

Type
Boolean

isDisabled()

Source:
Returns:

whether the field is disabled

Type
boolean

isEmpty()

Finds if the value of this field is empty.

Source:
Returns:

True if the field value is empty, false otherwise.

Type
Boolean

isEnabled()

Source:
Returns:

whether the field is enabled

Type
boolean

isRequired()

Determines whether the current field is required.

A field can be specified as required by either specifying required: true on the schema for a field or by
specifying a required array on the parent object with the name of the child field (as per json schema v 04).

Source:
Returns:
Type
boolean

isTopLevel()

Finds if this field is top level.

Source:
Returns:

True if this field is the top level one, false otherwise.

Type
Boolean

isValid()

Finds if this field is valid.

Source:
Returns:

True if the field is valid, false otherwise.

Type
Boolean

off(name)

Unregisters all listeners for an event.

Parameters:
Name Type Description
name
Source:

on(name, fn)

Registers an event listener.

Parameters:
Name Type Description
name
fn
Source:
Returns:
Type
*

onBlur(e)

Callback for when the field loses focus (blurs).

Default behavior is for the entire field to un-highlight.

Parameters:
Name Type Description
e

dom event

Source:

onChange(e)

Callback for when the field's value changes.

Default behavior is to update the control's value and notify.

Parameters:
Name Type Description
e

Event.

Source:

onDependentConceal()

Triggered when the field is being concealed as the result of a dependency or conditional calculation
that has determined that the field should be hidden.

Source:

onDependentReveal()

Triggered when the field is being revealed as the result of a dependency or conditional calculation
that has determined that the field should be shown.

Source:

onFocus(e)

Callback for when the field receives focus.

Default behavior is for the entire field to highlight.

Parameters:
Name Type Description
e

dom event

Source:

onMouseOut(e)

Callback for when the mouse moves out of the field.

Parameters:
Name Type Description
e
Source:

onMouseOver(e)

Callbeack for when the mouse moves over a field.

Parameters:
Name Type Description
e
Source:

postRender()

This method will be called after the field rendition is complete. It is served as a way to make final
modifications to the dom elements that were produced.

Source:

print()

Prints the field.

Source:

refresh(callback)

Redraws the field using the currently bound DOM element and view.

Parameters:
Name Type Description
callback
Source:

refreshValidationState(validateChildren, Function)

Forces the validation for a field to be refreshed or redrawn to the screen.

If told to check children, then all children of the container field will be refreshed as well.

Parameters:
Name Type Argument Description
validateChildren Boolean

whether to refresh validation for children

Function <optional>

optional callback when validation completes

Source:

reload()

Reloads the field.

Source:

render(view, callback)

This is the entry point method into the field. It is called by Alpaca for each field being rendered.

Renders this field into the container and creates a DOM element which is bound into the container.

Parameters:
Name Type Description
view Object | String

View to be used for rendering field (optional).

callback function

Post-Render callback (optional).

Source:

renderField(parentEl, onSuccess)

Renders the "field" outer element. This is usually the control or container.

Parameters:
Name Type Description
parentEl
onSuccess
Source:

renderFieldElements(callback)

Renders any field elements.

For controls or containers, this hook is used to inject additional dom elements into the outer field
dom element. Simple field types may choose not to implement this.

Parameters:
Name Type Description
callback function

callback

Source:

setDefault()

Resets value to default.

Source:

setTemplateDescriptor(template)

Sets the field template descriptor.

Parameters:
Name Type Description
template Object

descriptor

Source:

setup()

This method will be called right after the field instance is created. It will initialize
the field to get it ready for rendition.

Source:

setValue(value)

Sets the value of the field.

Parameters:
Name Type Description
value Any

Value to be set.

Source:

show()

Shows the field.

Source:

top()

Walks up the parent chain and returns the top most control. If no parents, then current control is top control.

Source:
Returns:

top most control

Type
Control

trigger(name, event)

Triggers an event

Parameters:
Name Type Description
name
event

Remainder of arguments will be passed to the event handler.

Source:
Returns:
Type
null

triggerUpdate()

Triggers any event handlers that listens to the update event of this field.

Source:

triggerWithPropagation(name, event, direction)

Triggers an event and propagates the event.

By default, the behavior is to propagate up to the parent chain (bubble up).

If "direction" is set to "down" and the field is a container, then the event is propagated down
to children (trickle down).

If "direction" is set to "both", then both up and down are triggered.

Parameters:
Name Type Description
name
event
direction

(optional) see above

Source:

updateDOMElement()

This gets called typically once per render. If a DOM element is moved within a container and it's indexing
changes, this will get called against to ensure that DOM properties are kept in sync.

Source:

validate(Boolean)

Validates this field and returns whether it is in a valid state.

Parameters:
Name Type Argument Description
Boolean <optional>

validateChildren whether to child controls.

Source:
Returns:

True if value of this field is valid, false otherwise.

Type
Boolean