Class: FieldModel

Drupal.quickedit. FieldModel

new Drupal.quickedit.FieldModel(options)

State of an in-place editable field in the DOM.

Name Type Description
options object

Options for the field model.

Extends

Members

staticDrupal.quickedit.FieldModel.statesArray.<string>

Sequence of all possible states a field can be in during quickediting.

acceptStateChange

Callback function for validating changes between states. Receives the previous state, new state, context, and a callback.

defaultsobject

el

The DOM element that represents this field. It may seem bizarre to have a DOM element in a Backbone Model, but we need to be able to map fields in the DOM to FieldModels in memory.

entity

A Drupal.quickedit.EntityModel. Its "fields" attribute, which is a FieldCollection, is automatically updated to include this FieldModel.

fieldID

A field ID, of the form <entity type>/<id>/<field name>/<language>/<view mode>

Example
"node/1/field_tags/und/full"

html

The full HTML representation of this field (with the element that has the data-quickedit-field-id as the outer element). Used to propagate changes from this field to other instances of the same field storage.

htmlForOtherViewModes

An object containing the full HTML representations (values) of other view modes (keys) of this field, for other instances of this field displayed in a different view mode.

id

The unique ID of this field within its entity instance on the page, of the form <entity type>/<id>/<field name>/<language>/<view mode>[entity instance ID].

Example
"node/1/field_tags/und/full[0]"

inTempStore

Is tracked by the EntityModel, is mirrored here solely for decorative purposes: so that FieldDecorationView.renderChanged() can react to it.

isChanged

The field is currently in the 'changed' state or one of the following states in which the field is still changed.

logicalFieldID

A logical field ID, of the form <entity type>/<id>/<field name>/<language>, i.e. the fieldID without the view mode, to be able to identify other instances of the same field on the page but rendered in a different view mode.

Example
"node/1/field_tags/und".

metadata

This field's metadata as returned by the QuickEditController::metadata().

state

In-place editing state of this field. Defaults to the initial state. Possible values: Drupal.quickedit.FieldModel.states.

Methods

staticDrupal.quickedit.FieldModel.followsStateSequence(from, to){bool}

Indicates whether the 'from' state comes before the 'to' state.

Name Type Description
from string

One of Drupal.quickedit.FieldModel.states.

to string

One of Drupal.quickedit.FieldModel.states.

Returns:
Type Description
bool Whether the 'from' state comes before the 'to' state.

Destroys the field model.

Name Type Description
options object

Options for the field model.

Find other instances of this field with different view modes.

Returns:
Type Description
Array An array containing view mode IDs.

Extracts the entity ID from this field's ID.

Returns:
Type Description
string An entity ID: a string of the format <entity type>/<id>.

Extracts the view mode ID from this field's ID.

Returns:
Type Description
string A view mode ID.

Set a value on the model

Name Type Description
key object | string

The key to set a value for.

val *

The value to set.

options object optional

Options for the model.

Returns:
Type Description
* The result of Backbone.Model.prototype.set with the specified parameters.

validate(attrs, options){string}

Validate function for the field model.

Name Type Description
attrs object

The attributes changes in the save or set call.

options object

An object with the following option:

Name Type Description
reason string optional

A string that conveys a particular reason to allow for an exceptional state change.

accept-field-states Array

An array of strings that represent field states that the entities must be in to validate. For example, if accept-field-states is ['candidate', 'highlighted'], then all the fields of the entity must be in either of these two states for the save or set call to validate and proceed.

Returns:
Type Description
string A string to say something about the state of the field model.