Search results

Validation

Validate the RichTextEditor’s value on form submission by applying Validation Rules and Validation Message to the RichTextEditor.

Validation Rules

The RichTextEditor is a textarea control. The RichTextEditor also provides the functionality of character count and its validation. So, you can validate the RichTextEditor’s value on form submission by applying Validation Rules and Validation Message to the RichTextEditor.

Rules Description
required Requires value for the RichTextEditor control.
minlength Requires the value to be of given minimum characters count.
maxlength Requires the value to be of given maximum characters count.

This sample is used to validate form using the obtrusive Validation. Type the values in RichTextEditor and the form enables the validation with the formvalidator rules by clicking on the submit externally. All rules are validated by the formvalidator rules.

tagHelper
controller.cs
<div class="control-section">
    <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">
                <ejs-richtexteditor id="form-support" name="rteForm" data-msg-containerid="dateError" created="created" showCharCount="true" maxLength="100" placeholder="Type something">
                </ejs-richtexteditor>
                <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>
    </div>
</div>

<script>
    var defaultRTE, formObject, options;
    function created() {
        options = {
            rules: {
                'rteForm': {
                    required: true
                }
            }
        };
        formObject = new ej.inputs.FormValidator('#form-element', options);
    };
    window.onload = function () {
        document.getElementById('validateSubmit').onclick = function () {
            getValue();
        };
    }
    function getValue() {
        formObject.validate();
    }
</script>
public class HomeController : Controller
{

    public ActionResult Index()
    {
        return View();
    }
}

Validation Message

The default error message for a rule can be customizable by defining it along with concern rule object as follows

tagHelper
controller.cs
<div class="control-section">
    <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">
                <ejs-richtexteditor id="form-support" name="rteForm" required data-required-message="* This field is required" data-msg-containerid="dateError" created="created" showCharCount="true" maxLength="100" placeholder="Type something">
                </ejs-richtexteditor>
                <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>
    </div>
</div>
<script>
    var formObject, options;
    function created() {
        options = {
            rules: {
                'rteForm': {
                    required: true,
                    minLength: [20, 'Need atleast 20 character length'],
                    maxLength: [100, 'Maximum 100 character only']
                }
            }
        };
        formObject = new ej.inputs.FormValidator('#form-element', options);
    };
    window.onload = function () {
        document.getElementById('validateSubmit').onclick = function () {
            getValue();
        };
    }
    function getValue() {
        formObject.validate();
    }
</script>
public class HomeController : Controller
{

    public ActionResult Index()
    {
        return View();
    }
}

Custom Placement of Validation Message

The FormValidator has an event customPlacement which can be used to place the error message from default position to desired custom location.

tagHelper
controller.cs
<div class="control-section">
    <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">
                <ejs-richtexteditor id="default" name="rteForm" required data-required-message="* This field is required" created="created" showCharCount="true" maxLength="100" placeholder="Type something">
                </ejs-richtexteditor>
                <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>
    </div>
</div>
<script>
    var formObject, options;
    function created() {
        options = {
            rules: {
                'rteForm': {
                    required: true,
                    minLength: [6, 'Need atleast 6 character length'],
                    maxLength: [100, 'Maximum 100 character only']
                }
            },
            customPlacement: function (inputElement, error) {
            document.getElementById('dateError').appendChild(error);
        }
    };
    formObject = new ej.inputs.FormValidator('#form-element', options);
    };
    window.onload = function () {
        document.getElementById('validateSubmit').onclick = function () {
            getValue();
        };
    }
    function getValue() {
        formObject.validate();
    }
</script>
public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}