Search results

Buttons in React InPlaceEditor component

The In-place Editor has an action for save and cancel using buttons. The saveButton and cancelButton properties accepts the ButtonModel objects for customizing the save and cancel button properties.

Buttons can be show or hide by setting a boolean value to the showButtons property.

Without buttons value actions will be performed by the following way.

  • actionOnBlur: By clicking out-side of the editor component it will get focus out and perform action based on this property value.
  • submitOnEnter: Pressing Enter key it performs the submit action, when this property set to true.

In the following sample, the content and cssClass properties of Button value assigned to the saveButton and cancelButton properties to customize its appearance. Also check or uncheck a checkbox buttons render or removed from the editor.

To restrict either save or cancel button rendering into a DOM, simply pass empty object {} in the saveButton or cancelButton properties.

For more details about buttons, refer this documentation section.

Source
Preview
App.tsx
App.css.jsx
App.jsx
index.jsx
import { ChangeEventArgs, CheckBoxComponent  } from '@syncfusion/ej2-react-buttons';
import { InPlaceEditorComponent } from '@syncfusion/ej2-react-inplace-editor';
import * as React from "react";
import './App.css';

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

  public model = { placeholder: 'Enter some text' };
  public saveButton = { content: 'Ok', cssClass: 'e-outline' };
  public cancelButton = { content: 'Cancel', cssClass: 'e-outline' };

  public onChange(e: ChangeEventArgs): void {
    (this.inplaceEditorObj as any).showButtons = e.checked;
    this.inplaceEditorObj.dataBind();
  }

  public render() {
    return (
    <div id='container'>
         <table className="table-section">
         <tbody>
             <tr>
                <td> ShowButtons: </td>
                <td>
                    <CheckBoxComponent id='enableBtn' checked={true} label='Show' change={ this.onChange = this.onChange.bind(this)  } />
                </td>
             </tr>
             <tr>
                 <td  className="sample-td"> Enter your name: </td>
                 <td  className="sample-td">
                    <InPlaceEditorComponent ref={(text) => { this.inplaceEditorObj = text! }} id='element' mode='Inline' value='Andrew' model={this.model} saveButton={this.saveButton} cancelButton={this.cancelButton}/>
                 </td>
              </tr>
            </tbody>
           </table>
     </div>
    );
  }
};
export default App;
import { CheckBoxComponent } from '@syncfusion/ej2-react-buttons';
import { InPlaceEditorComponent } from '@syncfusion/ej2-react-inplace-editor';
import * as React from "react";
import './App.css';
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.model = { placeholder: 'Enter some text' };
        this.saveButton = { content: 'Ok', cssClass: 'e-outline' };
        this.cancelButton = { content: 'Cancel', cssClass: 'e-outline' };
    }
    onChange(e) {
        this.inplaceEditorObj.showButtons = e.checked;
        this.inplaceEditorObj.dataBind();
    }
    render() {
        return (<div id='container'>
         <table className="table-section">
         <tbody>
             <tr>
                <td> ShowButtons: </td>
                <td>
                    <CheckBoxComponent id='enableBtn' checked={true} label='Show' change={this.onChange = this.onChange.bind(this)}/>
                </td>
             </tr>
             <tr>
                 <td className="sample-td"> Enter your name: </td>
                 <td className="sample-td">
                    <InPlaceEditorComponent ref={(text) => { this.inplaceEditorObj = text; }} id='element' mode='Inline' value='Andrew' model={this.model} saveButton={this.saveButton} cancelButton={this.cancelButton}/>
                 </td>
              </tr>
            </tbody>
           </table>
     </div>);
    }
}
;
export default App;
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));

See Also