Search results

Validation

In-place Editor control supports validation and it can be achieved by adding rules to the validationRules property, its child property key must be same as name property, otherwise validation not performed. Submitting data to the server or calling the validate method validation executed.

In the following sample, first editor value submitted without select any date, so the default error message will be displayed below the DatePicker element. Second editor configured with the validating event with the handler. In handler event errorMessage argument value modified and it will show below the DatePicker element.

Source
Preview
index.js
index.html
ej.base.enableRipple(true);

//Initialize In-place Editor control
var textObj = new ej.inplaceeditor.InPlaceEditor({
    mode: 'Inline',
    type: 'Date',
    name: 'Today',
    emptyText: 'dd/mm/yyyy',
    model: {
        placeholder: 'Select date'
    },
    validationRules : {
        Today: { required: true }
    }
});

//Render initialized In-place Editor control
textObj.appendTo('#textBox');

//Initialize In-place Editor control
var dateObj = new ej.inplaceeditor.InPlaceEditor({
    mode: 'Inline',
    type: 'Date',
    name: 'Today',
    emptyText: 'dd/mm/yyyy',
    model: {
        placeholder: 'Select date'
    },
    validationRules : {
        Today: { required: true }
    },
    validating: function(e) {
        e.errorMessage = 'Field should not be empty';
    }
});

//Render initialized In-place Editor control
dateObj.appendTo('#date');
<!DOCTYPE html><html lang="en"><head>
    <title>Essential JS 2 In-place Editor</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript In-place Editor Control">
    <meta name="author" content="Syncfusion">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="//cdn.syncfusion.com/ej2/material.css" rel="stylesheet">
    <link href="index.css" rel="stylesheet">
    
    
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js" type="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <table class="table-section">
            <tbody><tr>
                <td class="col-lg-6 col-md-6 col-sm-6 col-xs-6 control-title"> Default Error Message </td>
                <td class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
                    <div id="textBox"></div>
                </td>
            </tr>
            <tr>
                <td class="col-lg-6 col-md-6 col-sm-6 col-xs-6 control-title"> Customized Error Message </td>
                <td class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
                    <div id="date"></div>
                </td>
            </tr>
        </tbody></table>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
    ele.style.visibility = "visible";
 }   
        </script>
<script src="index.js" type="text/javascript"></script>
</body></html>
  • For more details about validation configuration, refer this documentation section.

  • For custom validation except specifying validationRules, specify errorMessage at validating event, message will be shown when the value is Empty.

See Also