Custom Content Form Field Object

item.getFields() returns the array of Field object. The Field object holds field data.

Method Parameter Required Returns Usage
field.getDefinition()

None

n/a

Returns field definition.
{
    "id": "<id>",
    "name": "<name>",
    "description": "<description>",
    "datatype": "<datatype>",
    "required": true|false,
    "valuecount": "single|list",
    "properties": {
      "caas-translation":  {
"inheritFromMaster": false,
"note": "",
"translate": true
}
    },
    "settings": {
        // field settings
    }
....
}

Settings property holds the field setting set for the field. Refer to Field Settings for more detail.

var fieldDefn = field.getDefinition();
field.getValue()

None

n/a

Returns field value. Refer to Field Types and Values for details.

var fieldValue = field.getValue();
field.getValueAt(index)

index

Non-negative number

yes

Returns field value at specified index. Works for multi-valued fields only.
var value = field.getValueAt(2);
field.validate(value, options)

value - value of the field

options - optional

yes Validates given field value and returns a Promise. When fulfills returns validation object.
// when valid
{
  isValid: true,
}
 
// when invalid
{
  isValid: false,
  errorMessageSummary: <error message>
  errorMessageDetail: <detail error message>
};
field.validate(fieldValue).then(function (validation) {
  if (validation && validation.isValid) {
    // handle valid field value
  } else {
    //display field validation error
  }
}).catch(function (error) {
  // handle error
});
field.setValue(value, options)

value - see section on field types and values

options - object with {silent: true|false}

no

options - optional

Sets given value for the field. When options with silent: true property is passed, form doesn't become dirty.

field.setValue(fieldValue);
field.setValue(fieldValue, {silent: true});
field.setValueAt(index, value, options)

index - Non-negative number

options - object with {silent: true|false}

index - yes

options - optional

Sets given value at the specified index for the field. Works only for multi-valued fields. When options with silent: true property is passed, form doesn't become dirty.

field.setValueAt(1, fieldValue);
field.setValueAt(1, fieldValue, {silent: true});
field.removeValueAt(index, options)

index - Non-negative number

options - object with {silent: true|false}

index - yes

options - optional

Removes value at the specified index. Works only for multi-valued fields. When options with silent: true property is passed, form doesn't become dirty.

field.removeValueAt(1);
field.removeValueAt(1, {silent: true});
field.openAssetPicker(options)

options - parameters to be sent to asset picker. Refer to options of mediaPicker and referencePicker sections in Embed UI API V2 for Oracle Content Management, a JavaScript API

options - Object

yes

Opens the asset picker and returns a Promise. When fulfilled returns an object containing id, name and type of the selected asset.
{
    id: <asset_id>,
    type: <asset_type>,
    name: <asset_name>
}
field.openAssetPicker().then(function (data) {
    var newValue = { id: data.id, type: data.type, name: data.name };
    field.setValue(newValue);
  }).catch(function (error) {
    // handle error
  });
field.on(event, handler)

event - string

handler - function that handles the event

yes

Currently only 'update' event is supported.

field.on('update', function(value){
  // called if the field changes in the UI
});
field.createCustomEditor(editorName, options)

editorName - name of the custom field editor

options - Object

Can have index, width and height.

index: If the field is multi-valued and the editor is needed to display field value for a specific index, then index can be passed.

width and height: This method returns a CustomEditor object with the given custom field editor rendered in an iframe. If the iframe containing the field editor needs to be in a certain initial size, then the width and height parameters can be passed. Note: custom field editors can have their own fixed sizes. They might also trigger to adjust the containing frame's size.

{
    index: <index>,
    width: <width>,
    height: <height>
}

editorName - yes

options - optional

Returns CustomEditor object
var fieldDefn = field.getDefinition(),
    isCustomEditor = fieldDefn.settings.caas.editor.hasOwnProperty('isCustom') ? fieldDefn.settings.caas.editor.hasOwnProperty('isCustom') : false;
if(isCustomEditor){
  var customFieldEditor = fieldDefn.settings.caas.editor.options.name;
  if(customFieldEditor){
    // create a dom element
    var container = document.createElement('div');
    document.body.appendChild(container);
    //create a custom editor for the field
    var customEditor = field.createCustomEditor(customFieldEditor);
    //add the custom editor's frame to the dom element
    container.appendChild(customEditor.getFrame());
    //listen to custom editor's change event
    customEditor.on('change', function (value) {
      //set the updated value to the field
      field.setValue(value);
    });
  }
}

Field Types and Values

Value parameter passed to field.setValue() or the value obtained from field.getValue() varies depending on the field data type and value count.

Datatype Value count Value Sample value

text

single

list

String

Array of strings

"my text"
["foo", "bar"]

largetext

single

list

String

Array of strings

"this is large text"
[
  "this is large text1",
  "this is large text2"
]

reference

single

list

Object with type, ID and name

Array of objects with type, ID and name

{
  "id": "CONTCB9A907A21E14B73A678CF39CF14A0FC",
  "type": "DigitalAsset",
  "name": "bird.jpg"
}
[
  {
    "id": "CONT58729B8B480F45E891D584736AC44CBA",
    "type": "DigitalAsset",
    "name": "cheetah.jpg"
  },
  {
    "id": "CONT393EBEDA72C84822A4C66D08CF2E4DBC",
    "type": "DigitalAsset",
    "name": "tiger.jpg"
  }
]

number

single

integer

200

decimal

single

decimal

245.25

boolean

single

true|false

true

datetime

single

Object with value and timezone where value is the date string with format

yyyy-MM-dd'T'HH:mm:ss.SSS+/-HH:mm

and time zone is the timezone string

{
  "value": "2020-08-21T03:20:00.000-04:00",
  "timezone": "America/New_York"
}

json

single

json string

{
  "name": "John",
  "age": 20,
  "gender": "Male"
}

Field Settings

Settings property holds the information about the settings of the field including editor name and any field specific validators. Following is a sample settings property for a multi-valued text data type with multi-select SelectBox editor. Editor name set in the field definition can be obtained from settings.caas.editor.name. Available editors associated with field types are listed under Field Types and Available Editors.

"settings": {
  "groupIndex": 3,
  "caas": {
    "description": "Fruits list",
    "valuecountRange": {
      "min": 1,
      "max": 3
    },
    "customValidators": [],
    "editor": {
      "name": "multi-selectbox",
      "options": {
        "multiple": true,
        "valueOptions": [
          {
            "value": "apple",
            "label": "apple"
          },
          {
            "value": "banana",
            "label": "banana"
          },
          {
            "value": "orange",
            "label": "orange"
          }
        ]
      }
    }
  }
}

Field Types and Available Editors

Data Type Single List
text

textbox

textarea

radiobuttonset

single-selectbox

single-selectbox-rest

textbox

textarea

checkboxset

multi-selectbox

multi-selectbox-rest

tagcloud

largetext

textarea

rich-text-editor

markdown-editor

textarea

rich-text-editor

markdown-editor

number

number-inc-dec

radiobuttonset

single-selectbox

n/a

decimal

number-inc-dec

radiobuttonset

single-selectbox

n/a

boolean

boolean-switch

boolean-checkbox

n/a

datetime

datepicker

datetimepicker

datetimepickerz

n/a

reference

mediapicker (in case of media)

itempicker

mediapicker (in case of media)

itempicker

json

json-form

json-textarea

n/a