How to add indication for unsaved values in React In-place Editor

10 Aug 20267 minutes to read

Add custom indication for unsaved input values by using the actionSuccess event when data is not submitted to the server.

In this sample, the actionSuccess event is configured and the URL property is not set. When the submit button is clicked, the editor value is saved locally and server submission is prevented because the URL property is not configured.

The actionSuccess event will trigger the handler function with null argument values. In the handler, the primaryKey property is checked to determine if it is empty. If the primaryKey is empty, a custom CSS class is added to the e-value-wrapper element to apply custom styling that indicates unsaved data.

To save input values locally without sending to the server, leave the URL property empty.

[Class-component]

import { isNullOrUndefined as isNOU } from '@syncfusion/ej2-base';
import { InPlaceEditorComponent } from '@syncfusion/ej2-react-inplace-editor';
import * as React from 'react';
import './App.css';
class App extends React.Component {
    inplaceEditorObj;
    model = { placeholder: 'Enter some text' };
    actionSuccess(e) {
        const keyVal = 'PrimaryKey';
        const primeKey = e.data[keyVal];
        if (isNOU(primeKey) || primeKey === '') {
            document.querySelector('.e-editable-value').classList.add('e-send-error');
        }
    }
    render() {
        return (<div id='container'>
        <span className="content-title"> Enter your name: </span>
        <InPlaceEditorComponent id='customtextbox' mode='Inline' value='Andrew' model={this.model} actionSuccess={this.actionSuccess = this.actionSuccess.bind(this)}/>
     </div>);
    }
}
export default App;
import { isNullOrUndefined as isNOU } from '@syncfusion/ej2-base';
import { ActionEventArgs, InPlaceEditorComponent } from '@syncfusion/ej2-react-inplace-editor';
import * as React from 'react';
import './App.css';

class App extends React.Component<{},{}> {
  public inplaceEditorObj: InPlaceEditorComponent;

  public model = { placeholder: 'Enter some text' };

  public actionSuccess(e: ActionEventArgs): void {
    const keyVal = 'PrimaryKey';
    const primeKey: string = e.data[keyVal];
    if (isNOU(primeKey) || primeKey === '') {
      ((document.querySelector('.e-editable-value') as any)).classList.add('e-send-error');
    }
  }

  public render() {
    return (
    <div id='container'>
        <span className="content-title"> Enter your name: </span>
        <InPlaceEditorComponent id='customtextbox' mode='Inline' value='Andrew' model={this.model} actionSuccess={ this.actionSuccess = this.actionSuccess.bind(this) } />
     </div>
    );
  }
}

export default App;

[Functional-component]

import { isNullOrUndefined as isNOU } from '@syncfusion/ej2-base';
import { InPlaceEditorComponent } from '@syncfusion/ej2-react-inplace-editor';
import * as React from 'react';
import './App.css';
function App() {
    let inplaceEditorObj;
    let model = { placeholder: 'Enter some text' };
    function actionSuccess(e) {
        const keyVal = 'PrimaryKey';
        const primeKey = e.data[keyVal];
        if (isNOU(primeKey) || primeKey === '') {
            document.querySelector('.e-editable-value').classList.add('e-send-error');
        }
    }
    return (<div id='container'>
        <span className="content-title"> Enter your name: </span>
        <InPlaceEditorComponent id='customtextbox' mode='Inline' value='Andrew' model={model} actionSuccess={actionSuccess = actionSuccess.bind(this)}/>
     </div>);
}
export default App;
import { isNullOrUndefined as isNOU } from '@syncfusion/ej2-base';
import { ActionEventArgs, InPlaceEditorComponent } from '@syncfusion/ej2-react-inplace-editor';
import * as React from 'react';
import './App.css';

function App () {
  let inplaceEditorObj: InPlaceEditorComponent;

  let model = { placeholder: 'Enter some text' };

  function actionSuccess(e: ActionEventArgs): void {
    const keyVal = 'PrimaryKey';
    const primeKey: string = e.data[keyVal];
    if (isNOU(primeKey) || primeKey === '') {
      ((document.querySelector('.e-editable-value') as any)).classList.add('e-send-error');
    }
  }

    return (
    <div id='container'>
        <span className="content-title"> Enter your name: </span>
        <InPlaceEditorComponent id='customtextbox' mode='Inline' value='Andrew' model={model} actionSuccess={ actionSuccess = actionSuccess.bind(this) } />
     </div>
    );

}

export default App;