Options
All
  • Public
  • Public/Protected
  • All
Menu

Type parameters

  • Model = any

Hierarchy

  • ContentEditorForm

Index

Constructors

constructor

  • new ContentEditorForm(connection: ClientConnection, readOnly: boolean): ContentEditorForm

Properties

Private connection

connection: ClientConnection

Private onChangeStack

onChangeStack: Array<onReadOnlyChangeHandler>

Private onModelStack

onModelStack: Array<onModelChangeHandler>

readOnly

readOnly: boolean

Methods

getValue

  • getValue(): Promise<Body<Model>>

isValid

  • isValid(model: Body<Model>): Promise<Boolean>
  • Check if your model is valid

    Parameters

    • model: Body<Model>

      The model you wish to test

      Gives the current validity of the form returns a boolean

      Example

      const isValid = await sdk.form.isValid({ title: 'Hello World' })
      
      console.log(isValid) // false
      

    Returns Promise<Boolean>

onModelChange

  • On changes to the model not explicitly handled by the extension, this method will be called in order to keep model in sync with Dynamic Content

    Parameters

    Returns any

    unsubscribe callback

    Example

    let currentModel;
    
    sdk.form.onModelChange(model => {
     currentModel = model;
    });
    
    const unsubscribe = sdk.form.onModelChange((errors, model) => {
     setErrors(errors);
     setModel(model)
    });
    
    unsubscribe()
    

onReadOnlyChange

  • Allows you to provide a callback to be executed after the readonly state changes. This method can be chained to append multiple callbacks.

    Parameters

    Returns ContentEditorForm

    ContentEditorForm

    Example

    const container = document.querySelector('.container');
    const inputs = Array.from(document.querySelectorAll('input'));
    
    sdk.form
     .onReadOnlyChange(setReadOnlyClass)
     .onReadOnlyChange(disableInputs)
    
    function disableInputs(readOnly)  {
      inputs.forEach(input => {
        input.style.pointerEvents = readOnly ? 'none' : ''
      })
    }
    
    function setReadOnlyClass(readOnly) {
      container.classList[readOnly ? 'add' : 'remove']('read-only')
    }
    

setValue

  • Set the current model state

    Parameters

    • value: Body<Model>

      to set as model

    Returns Promise<ErrorReport[] | void>

    an array containing any JSON Schema errors found.

    Example

    const sdk = await init();
     try {
        await sdk.form.setValue({ title: 'hello world' });
     } catch (errors) {
       if (errors.length) {
          console.log(errors);
       }
     }
    

validate

  • Check the validation of your model. Returns an array containing any JSON Schema errors found.

    Parameters

    • model: Body<Model>

      The model you wish to test

      If you want to validate a field model and get back an error report ErrorReport

      Example

      const errors = await sdk.form.validate({ title: 'Hello World' })});
      
      if (errors && errors.length) {
        errors.forEach(error => console.log(error));
      } else {
        // valid
      }
      

    Returns Promise<ErrorReport[] | void>

Legend

  • Constructor
  • Property
  • Method
  • Private property
  • Private method
  • Property
  • Inherited property
  • Protected property

Generated using TypeDoc