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. |
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.
-
<private> _render(callback)
-
Internal method for processing the render.
Parameters:
Name Type Description callback
function Post-render callback.
-
_validateCustomValidator()
-
Validates using user provided validator.
-
_validateDisallow()
-
Checks whether the field value is allowed or not.
Returns:
True if the field value is allowed, false otherwise.
- Type
- Boolean
-
_validateOptional()
-
Validates against required property.
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
-
bindData()
-
Binds the data into the field. Called at the very end of construction.
-
clear()
-
Clears the field and resets the field to its original value.
-
destroy()
-
Purges any event listeners and remove this field from the DOM.
-
disable()
-
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.
-
enable()
-
Enables the field.
-
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
-
focus()
-
Focuses on the field.
If a callback is provided, the callback receives the control focused upon.
-
getBaseFieldType()
-
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.
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
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
Returns:
- Type
- Array
-
getDescription()
-
Returns field description.
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.Returns:
The rendered DOM element.
- Type
- Object
-
getFieldType()
-
Returns a string that identifies the type of field.
Returns:
- Type
- string
-
getId()
-
Returns the id of the field.
Returns:
Field id.
-
getMessage(key)
-
View and locale friendly retrieval of messages.
Parameters:
Name Type Description key
-
getName()
-
Retrieves the name of this element at the current level of JSON data.
Returns:
- Type
- *
-
<private> getOptionsForOptions()
-
Returns Alpaca options for the Alpaca options that are managed by this class.
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.
Returns:
Alpaca options for the schema properties that are managed by this class.
- Type
- Object
-
getParent()
-
Returns this field's parent.
Returns:
Field parent.
- Type
- Alpaca.Field
-
getPath()
-
Retrieves the path to this element in the graph of JSON data.
Returns:
the path to this element
- Type
- string
-
<private> getSchemaOfOptions()
-
Returns JSON schema of the Alpaca options that are managed by this class.
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.
Returns:
JSON schema of the schema properties that are managed by this class.
- Type
- Object
-
getTemplateDescriptor()
-
Returns the field template descriptor.
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".Returns:
field template descriptor id
- Type
- String
-
getTitle()
-
Returns field title.
Returns:
Field title.
- Type
- String
-
getType()
-
Returns schema data type.
Returns:
Schema data type.
- Type
- String
-
getValue()
-
Returns the value of this field.
Returns:
value Field value.
- Type
- Any
-
handleValidate()
-
Performs validation.
-
hide()
-
Hides the field.
-
initEvents()
-
Initializes event handling.
-
initTemplateDescriptor()
-
Sets up default rendition template from view.
-
isContainer()
-
Finds if this field is a container of other fields.
Returns:
True if it is a container, false otherwise.
- Type
- Boolean
-
isDisabled()
-
Returns:
whether the field is disabled
- Type
- boolean
-
isEmpty()
-
Finds if the value of this field is empty.
Returns:
True if the field value is empty, false otherwise.
- Type
- Boolean
-
isEnabled()
-
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).Returns:
- Type
- boolean
-
isTopLevel()
-
Finds if this field is top level.
Returns:
True if this field is the top level one, false otherwise.
- Type
- Boolean
-
isValid()
-
Finds if this field is valid.
Returns:
True if the field is valid, false otherwise.
- Type
- Boolean
-
off(name)
-
Unregisters all listeners for an event.
Parameters:
Name Type Description name
-
on(name, fn)
-
Registers an event listener.
Parameters:
Name Type Description name
fn
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
-
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.
-
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. -
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. -
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
-
onMouseOut(e)
-
Callback for when the mouse moves out of the field.
Parameters:
Name Type Description e
-
onMouseOver(e)
-
Callbeack for when the mouse moves over a field.
Parameters:
Name Type Description e
-
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. -
print()
-
Prints the field.
-
refresh(callback)
-
Redraws the field using the currently bound DOM element and view.
Parameters:
Name Type Description callback
-
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
-
reload()
-
Reloads the field.
-
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).
-
renderField(parentEl, onSuccess)
-
Renders the "field" outer element. This is usually the control or container.
Parameters:
Name Type Description parentEl
onSuccess
-
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
-
setDefault()
-
Resets value to default.
-
setTemplateDescriptor(template)
-
Sets the field template descriptor.
Parameters:
Name Type Description template
Object descriptor
-
setup()
-
This method will be called right after the field instance is created. It will initialize
the field to get it ready for rendition. -
setValue(value)
-
Sets the value of the field.
Parameters:
Name Type Description value
Any Value to be set.
-
show()
-
Shows the field.
-
top()
-
Walks up the parent chain and returns the top most control. If no parents, then current control is top control.
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.
Returns:
- Type
- null
-
triggerUpdate()
-
Triggers any event handlers that listens to the update event of this field.
-
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
-
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. -
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.
Returns:
True if value of this field is valid, false otherwise.
- Type
- Boolean