Custom indication in EJ2 TypeScript In place editor control

19 Apr 20233 minutes to read

You can add custom indication to unsaved input value by using the actionSuccess event, when data not submitted to the server.

In this sample, the actionSuccess event configured and the URL property not included. Then submit button clicked, the current editor value saved into input and data sending to server action prevented due to the URL property not configured.

But actionSuccess event will trigger the handler function with null argument values. In handler function data property primaryKey value checked, whether it empty or not. If it is empty custom class, added in the e-value-wrapper element to customize its styles.

To send input value to local, set the URL property as empty.

import { isNullOrUndefined as isNOU } from '@syncfusion/ej2-base';
import { InPlaceEditor, ActionEventArgs } from '@syncfusion/ej2-inplace-editor';

let editObj: InPlaceEditor = new InPlaceEditor({
    mode: 'Inline',
    value: 'Andrew',
    model: {
        placeholder: 'Enter some text'
    },
    actionSuccess: function(e: ActionEventArgs): void {
        let pk: string = e.data['PrimaryKey'];
        if (isNOU(pk) || pk === '') {
            document.querySelector('.e-editable-value').classList.add('e-send-error');
        }
    }
});
editObj.appendTo('#element');
<!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://cdn.syncfusion.com/ej2/25.1.35/material.css" rel="stylesheet" />
    <link href="index.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'>
        <span class="content-title"> Enter your name: </span>
        <div id='element'></div>
    </div>
</body>

</html>