This is a form control that wraps a new instance of a
Code Mirror editor (version 5.20.2)
which allows user input to be syntax highlighted according to the configured
editMode.
The default editing mode is for XML but other modes are available (see
the Code Mirror documentation for details). In addition to supporting all the
standard configuration attributes for all
form controls it is
also possible to configure the
[height]editMode
and [width]editMode
of the editor.
- Copyright:
- Copyright (C) 2005-2020 Alfresco Software Limited
- License:
- GNU Lesser General Public License, see: Open Source Licensing
- Source:
Example
{
name: "alfresco/forms/controls/CodeMirrorEditor",
config: {
label: "Enter script",
description: "Add your JavaScript code here",
name: "js",
editMode: "javascript"
}
}
Members
-
cssRequirements :Array
-
An array of the CSS files to use with this widget.
Type:
- Array
-
editMode :string
-
This is the editor mode for the embedded CodeMirror editor. By default it is "xml". This will control the syntax highlighting.
Type:
- string
- Default Value:
- "xml"
- Source:
-
height :number
-
The height of the editor (in pixels).
Type:
- number
- Default Value:
- 300
- Source:
-
isPromisedWidget :boolean
-
Indicates that the call to createFormControl is going to return a "promise" rather than an actual widget because it needs to require the additional AMD resources first.
Type:
- boolean
- Default Value:
- true
- Source:
-
width :number
-
The width of the editor (in pixels).
Type:
- number
- Default Value:
- 600
- Source:
Methods
-
createFormControl()
-
Instantiates a new JSON editor, places it in the template DOM and setups the change events. The ACE module sneakily overwrites the "require" variable which will prevent subsequent calls to the Dojo require from working, therefore it's necessary to keep a reference to the original function and then undo the damage once ACE has been loaded... Although we could have included these in the modules "define" statement and have them preloaded into the Dojo cache would break the page as soon as the ACE module is processed :(
-
getValue() → {string}
-
Overrides the inherited function to call the "getValue" function on the editor. This returns the JSON text rather than a JavaScript object.
Returns:
The JSON value entered into the editor- Type
- string
-
getWidgetConfig()
-
onEditorChange()
-
A callback handler that is hitched to change events in the instantiation of the JSON editor.
-
onResizeEvent()
-
This is the callback function for resize events relating to the DOM element of this widget. It's primary use is to call the CodeMirror refresh function and has been added to handle the scenario where an editor is included in an AlfDialog. The AlfDialog publishes a resize event when it is first opened and this can be used to ensure that the editor is rendered correctly (because otherwise it doesn't!)
-
placeWidget()
-
Overrides the inherited function primarily to prevent an unnecessary warning being logged. But additionally this calls the refresh function on the Code Mirror editor to ensure it is rendered correctly.
-
processValidationRules() → {boolean}
-
Extends the default function to see if the editor any errors. Currently the error checking is not actually implemented.
Returns:
True if the editor content is valid and false otherwise.- Type
- boolean
-
setupChangeEvents()
-
Overrides to prevent any action from occurring.
-
setupEditor()
-
Creates and configures the CodeMirror editor.