Embed Code Editors
Overview
This article introduces how to embed the Ace.js editor into records of a Kintone App.
Ace.js
Ace.js is an embeddable code editor for web pages. It matches features of other popular code editors (such as Sublime Text), and can be easily customized based on preference.
Sample Image
Code Editing
The Ace editor is displayed in the Record Create and Edit page. When the user navigates to the Record Details page, a read-only version of the Ace editor is displayed. The user can re-edit the code by navigating to the Record Edit page.
Syntax Errors
Codes that do not follow the specified syntax will be noted as errors inside the Ace.js code editor.
Prepare the App
Create the form
Create an App with the following fields.
Field Type | Field Code / Element ID | Field Name |
---|---|---|
Text Area | code | Code |
Blank space | editor | -- |
The form should look like the following screenshot.
Set the library
This example uses Ace.js v1.3.3. Set the following URL into the Upload JavaScript for PC option of the App's JavaScript and CSS Customization settings .
- https://js.kintone.com/ace/v1.3.3/ace.js
Sample Code
Set the JavaScript file
Prepare the following JavaScript code in a text editor and navigate to the Kintone App's settings. Upload the file into the Upload JavaScript for PC option of the JavaScript and CSS Customization settings .
|
|
Set the CSS file
Prepare the following CSS in a text editor and navigate to the Kintone App's settings. Upload the file into the Upload CSS for PC option of the JavaScript and CSS Customization settings .
|
|
Attention
Caution: The order in which JavaScript and CSS are uploaded to an app matters. In this example, ensure that the Ace.js library is uploaded before the JavaScript file. You can change the order of uploads by clicking and dragging on the arrows for each item on the Upload JavaScript / CSS page.
Update the Settings
The files set in the JavaScript and CSS Customization settings should look like the following.
Click Save, and then on Update App. Create a new record to view the embedded code editor.
Code Explanation
When the record create or record edit event is triggered, the Text Area field is hidden, and the Ace editor is displayed on the Blank Space field. When the record is saved, the contents inside the Ace editor are saved into the Text Area field. This data in the Text Area field is later used to populate the contents of the Ace editor when the record edit event is triggered. When the record details event is triggered, the Text Area field is hidden again, and a "read-only" version of the Ace editor is displayed on the Blank space field.