Custom Content Form SDK Object

The callback function passed to contentFormSDK.init() gets an instance of the SDK object that provides following methods:

Method Parameter Required Returns Usage
sdk.getLocale() None n/a Returns the current locale of the interface.
var locale = sdk.getLocale();
sdk.getItem() None n/a Returns the Item object.
var item = sdk.getItem();
sdk.getType() None n/a

Returns Type object of the content item's content type.

var type = sdk.getType();
sdk.resize(size) Object with height and width. no

Resizes the frame to specified size. When no size is specified, it will resize the iframe to the size of its body.

sdk.resize({
    width: '80%',
    height: '80%'
});
sdk.registerFormValidation(callback) Function that handles the validation of the form. yes

This callback will be invoked to validate the form when saving.

sdk.registerFormValidation(function(){
    //handle form validation
});
sdk.previewAsset(options) options- Object with id.

{id:<asset_id>}

yes Opens up asset preview drawer
sdk.previewAsset({
    id: '<asset_id>'
});
sdk.getRepositoryDefaultLanguage() None n/a Returns the default language of the current repository.
var lang = sdk.getRepositoryDefaultLanguage();
sdk.createAsset(options) options- Object with type
{
  type:<type_name>, 
  header: { 
    <header-button>: true|false 
  },
  callBack: function(){} 
}

type -optional;

header - optional;

callBack - optional, the function is to be invoked when newly created asset is saved.

When the type is given, it opens up the create item drawer. When the type is not given, it opens up the dialog to choose a type. And after the type is chosen, it opens the create item drawer.

When invoking sdk.createAsset(), if its response needs to be handled once, then pass resolve and reject callbacks to the Promise. When the Promise is fullfilled, it returns a newly created asset response, but returns error object containing the error response when rejected.

sdk.createAsset({ type: '<type-name>' }).then(function (response) {
  // handle response    
}).catch(function (error) { 
  // handle error
});

When invoking sdk.createAsset(), if its response needs to be handled every time when save happens in the drawer that creates new asset, then a callBack parameter should be passed.

sdk.createAsset({ 
  type: '<type_name>', 
  header: { save: true }, 
  callBack: function(response){ 
    // this function will be  
    // invoked every time save occurs 
  }
});

callBack option may be passed if the save option in the header is set to true and the form invoking sdk.createAsset() needs to listen to save.

sdk.createAsset({ type: '<type-name>' }).then(function (response) { 
 // handle response
}).catch(function (error) { 
 // handle error
});
sdk.createAsset({ 
  type: '<type_name>', 
  header: { save: true }, 
  callBack: function(response){ 
    // handle response 
  } 
});
sdk.editAsset(options) options- Object with id
{
  id: <asset_id>
  header: {      
    <header-button>: true|false    
  },
  callBack: function(){}
}

id - required;

header - optional;

callBack - optional, the function is to be invoked when asset being edited is saved.

When the given asset is a content item, it opens up edit item drawer. When the given asset is a digital asset, it opens edit attributes drawer.

When invoking sdk.editAsset(), if its response needs to be handled once, then pass resolve and reject callbacks to the Promise. When the Promise is fullfilled, it returns the edited asset's response; but returns error object containing the error response when rejected.

sdk.editAsset({ id: '<asset_id>' }).then(function (response) {  
  // handle response
}).catch(function (error) {  
  // handle error
});

When invoking sdk.editAsset(), if its response needs to be handled every time when save happens in the drawer that edits the asset, then a callBack parameter should be passed.


sdk.editAsset({ 
  id: '<asset_id>', 
  header: { save: true }, 
  callBack: function(response){ 
    // handle response 
  } 
});

callBack option may be passed if the save option in the header is set to true and the form invoking sdk.editAsset() needs to listen to save.

sdk.editAsset({ id: '<asset_id>' }).then(function (response) {
  // handle response
}).catch(function (error) {
  // handle error
});
sdk.editAsset({ 
  id: '<asset_id>', 
  header: { save: true }, 
  callBack: function(response){ 
    // handle response 
  } 
});
sdk.getRepositoryId() None n/a Returns Id of the current repository.
var currentRepo =
    sdk.getRepositoryId();
sdk.isMediaEditble(options) options- Object with id

{id: <asset_id>}

id - required Whether or not the media of the given digital asset is editable.

{ isEditable: true|false, reason: '' | <reason text when not editable> }

sdk.isMediaEditble({ id: '<asset_id>' }).then(function (response) {
  if(response && response.isEditable){
  //  try editing
 }
}).catch(function (error) {
  //handle error
});
sdk.editMedia(options) options- Object with id id - required Opens edit media drawer. When the digital asset's media is an image, opens image editor drawer. When digital asset's media is an advanced video, opens video editor drawer.
sdk.editMedia({ id: <asset_id> }).then(function (response) {
  // handle response
}).catch(function (error) {
   // handle error
});
sdk.isAssetEditble(options) options- Object with id id - required Whether or not the asset is editable.

{ isEditable: true|false, reason: '' | <reason text when not editable> }

sdk.isAssetEditble({ id: '<asset_id>' }).then(function (response) {
  if(response && response.isEditable){
  //  try editing
 }
}).catch(function (error) {
  //handle error
});
sdk.getDirection() None n/a

Returns the current direction of the UI.

Either ltr or rtl

// when the form wants to handle and support
// directionality
let dir = sdk.getDirection();
if(dir){
document.querySelector("html").setAttribute("dir", dir);
}
sdk.canCreateAsset(options) options - object with type type - required

Whether or not the asset of a given type can be created.

{    
  canCreate: true|false,    
  reason: '' | <reason text when not able to create>
}

sdk.canCreateAsset({ type: '<asset_type>' }).then(function (response) {  
  if(response && response.canCreate){   
  //  try creating  
  }
}).catch(function (error) {  
  //handle error
});

SDK Constants

The custom content form SDK has the following field data type constants:

sdk.dataTypes.TEXT
sdk.dataTypes.LARGETEXT
sdk.dataTypes.REFERENCE
sdk.dataTypes.NUMBER
sdk.dataTypes.DECIMAL
sdk.dataTypes.BOOLEAN
sdk.dataTypes.DATETIME
sdk.dataTypes.JSON