Buttons in Angular Inplace editor component
27 Apr 20243 minutes to read
The In-place Editor has an option to save and cancel using buttons. The saveButton and cancelButton properties accept the ButtonModel objects for customizing the save and cancel button properties.
Buttons can be show or hide by sets a Boolean value to the showButtons property.
Without buttons value will be processed via the following ways.
- actionOnBlur: By clicking out side the editor component get focus out and do action based on this property value.
-
submitOnEnter: Pressing
Enter
key it performs the submit action, if this property set totrue
.
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.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { InPlaceEditorAllModule } from '@syncfusion/ej2-angular-inplace-editor'
import { CheckBoxModule, ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { Component, ViewChild } from '@angular/core';
import { InPlaceEditorComponent } from '@syncfusion/ej2-angular-inplace-editor';
import { ChangeEventArgs } from '@syncfusion/ej2-buttons';
@Component({
imports: [
InPlaceEditorAllModule, CheckBoxModule, ButtonModule
],
standalone: true,
selector: 'app-root',
template: `
<div id='container'>
<table class="table-section">
<tr>
<td> ShowButtons: </td>
<td>
<ejs-checkbox label="Show" [checked]="true" (change)="onChange($event)"></ejs-checkbox>
</td>
</tr>
<tr>
<td class="sample-td"> Enter your name: </td>
<td class="sample-td">
<ejs-inplaceeditor #element id="element" mode="Inline" value="Andrew" [model]="model" [saveButton]="saveButton" [cancelButton]="cancelButton"></ejs-inplaceeditor>
</td>
</tr>
</table>
</div>
`
})
export class AppComponent {
@ViewChild('element') editorObj?: InPlaceEditorComponent;
public model: Object = { placeholder: 'Enter some text' };
public saveButton: object = { content: 'Ok', cssClass: 'e-outline'};
public cancelButton: object = { content: 'Cancel', cssClass: 'e-outline'};
public onChange(e: ChangeEventArgs): void {
(this.editorObj as InPlaceEditorComponent).showButtons = e.checked as boolean;
this.editorObj?.dataBind();
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));