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.

razor
controller.cs
@using Syncfusion.EJ2.InPlaceEditor;

<div id='container'>
    <table class="table-section">
        <tr>
            <td class="col-lg-6 control-title"> Default Error Message </td>
            <td class="col-lg-6">
                @Html.EJS().InPlaceEditor("textBox").Mode(RenderMode.Inline).Type(Syncfusion.EJ2.InPlaceEditor.InputType.Date).Name("Today").EmptyText("dd/mm/yyyy").Model(ViewBag.dateModel).ValidationRules(ViewBag.validationRules).Render()
            </td>
        </tr>
        <tr>
            <td class="col-lg-6 control-title"> Customized Error Message </td>
            <td class="col-lg-6">
                @Html.EJS().InPlaceEditor("date").Mode(RenderMode.Inline).Type(Syncfusion.EJ2.InPlaceEditor.InputType.Date).Name("TodayCustom").EmptyText("dd/mm/yyyy").Model(ViewBag.dateModel).ValidationRules(ViewBag.ValidationModel).Validating("validating").Render()
            </td>
        </tr>
    </table>
</div>

<style>
    #container {
        display: flex;
        justify-content: center;
    }

    .table-section {
        margin: 0 auto;
    }

    td {
        padding: 20px 0;
        min-width: 230px;
        height: 100px;
    }

    .control-title {
        font-weight: 600;
        padding-right: 20px;
        text-align: right;
    }
</style>
<script>
    function validating(e) {
        e.errorMessage = 'Field should not be empty';
    }
</script>
public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewBag.dateModel = new { placeholder = "Select date" };
        ViewBag.validationRules = new { Today = new { required = true } };
        ViewBag.ValidationModel = new { TodayCustom = new { required = true } };
        return View();
    }
}

The output will be as follows.

validation

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