Contents
- Render the Rich Text Editor
- Obtain the value
- See Also
Having trouble getting help?
Contact Support
Contact Support
Form support in EJ2 TypeScript Rich text editor control
18 Apr 20236 minutes to read
The following sample demonstrates how to get the Rich Text Editor value in button click.
Render the Rich Text Editor
Render the Rich Text Editor in form.
<form id="myForm" class="form-vertical">
<div class="form-group">
<textarea id="defaultRTE" name="defaultRTE" required maxlength="100" minlength="20" data-msg-containerid="dateError"> </textarea>
<div id="dateError" style="padding-top: 10px"></div>
</div>
<div style="text-align: center">
<button id="validateSubmit" class="samplebtn e-control e-btn" type="submit" data-ripple="true">Submit</button>
<button id="resetbtn" class="samplebtn e-control e-btn" type="reset" data-ripple="true">Reset</button>
</div>
</form>
Obtain the value
Upon submitting the form, the getValue
method will be triggered. Through the FormData
class, get the Rich Text Editor value.
import { enableRipple } from '@syncfusion/ej2-base';
enableRipple(true);
import { RichTextEditor, Toolbar, Link, Image, HtmlEditor, Count, QuickToolbar } from '@syncfusion/ej2-richtexteditor';
import { FormValidator } from '@syncfusion/ej2-inputs';
RichTextEditor.Inject(Toolbar, Link, Image, HtmlEditor, Count, QuickToolbar);
let defaultRTE: RichTextEditor = new RichTextEditor({ showCharCount: true, maxLength: 100, placeholder: 'Type something' });
defaultRTE.appendTo('#defaultRTE');
let formObject = new FormValidator('#form-element');
document.getElementById('validateSubmit').onclick = function (){
getValue();
}
function getValue(){
let form = document.getElementById('form-element');
let formData = new FormData(form);
let rteValue = formData.get('defaultRTE');
alert(rteValue);//Store the value to the data base.
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 Rich Text Editor</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-richtexteditor/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-lists/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id="content" class="box-form" style="margin: 0 auto; width:750px; padding:25px">
<form id="form-element" class="form-vertical">
<div class="form-group">
<textarea id="defaultRTE" required name="defaultRTE" class="form-control"></textarea>
<div id="dateError" style="padding-top: 10px"></div>
</div>
<div class="form-group">
<div class="col-sm-3 control-label"></div>
<div class="col-sm-6">
<div id='error'></div>
</div>
</div>
<div style="text-align: center">
<button id="validateSubmit" class="samplebtn e-control e-btn">Submit</button>
<button id="resetbtn" class="samplebtn e-control e-btn" type="reset" data-ripple="true">Reset</button>
</div>
</form>
</div>
</div>
</body>
</html>