All Projects → ngneat → Edit In Place

ngneat / Edit In Place

Licence: mit
A flexible and unopinionated edit in place library for Angular applications

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Edit In Place

Formeditor
A form builder editor for Umbraco 7 - let your editors build forms easily with this free package.
Stars: ✭ 95 (-22.76%)
Mutual labels:  form
Formcat
A simple and easy way to control forms in React using the React Context API
Stars: ✭ 106 (-13.82%)
Mutual labels:  form
React Form With Constraints
Simple form validation for React
Stars: ✭ 117 (-4.88%)
Mutual labels:  form
Aform
AForm 是组件化、自动化、模型驱动的表单开发框架,它可以极大地提高您开发信息系统的生产力!
Stars: ✭ 96 (-21.95%)
Mutual labels:  form
Formsy Semantic Ui React
Formsy-React wrappers for Semantic-Ui-React's form components
Stars: ✭ 103 (-16.26%)
Mutual labels:  form
Jhform
JhForm - 自定义表单工具,更加简单,快捷的创建表单、设置页面
Stars: ✭ 108 (-12.2%)
Mutual labels:  form
Ngx Dynamic Form Builder
FormBuilder + class-transformer + class-validator = dynamic form group builder for Angular10+
Stars: ✭ 93 (-24.39%)
Mutual labels:  form
Vue Form Components
Clean & minimal vue form elements and form builder with validation
Stars: ✭ 120 (-2.44%)
Mutual labels:  form
Framy Css
Very simple CSS Framework
Stars: ✭ 103 (-16.26%)
Mutual labels:  form
React Native Form Builder
Handle your forms in a smart way
Stars: ✭ 113 (-8.13%)
Mutual labels:  form
Formchimp
A customizable MailChimp ajax plugin for jQuery
Stars: ✭ 98 (-20.33%)
Mutual labels:  form
Lodash Form Collector
a form collector powered by lodash that support any frontend framework.
Stars: ✭ 101 (-17.89%)
Mutual labels:  form
Webapiclient
An open source project based on the HttpClient. You only need to define the c# interface and modify the related features to invoke the client library of the remote http interface asynchronously.
Stars: ✭ 1,618 (+1215.45%)
Mutual labels:  form
Educenter Hugo
Educenter is an educational website template. It can be used as an online teaching platform, school and university websites
Stars: ✭ 96 (-21.95%)
Mutual labels:  form
Form For
ReactJS forms made easy
Stars: ✭ 118 (-4.07%)
Mutual labels:  form
Purescript Halogen Formless
Painless forms for Halogen
Stars: ✭ 94 (-23.58%)
Mutual labels:  form
Jafar
🌟!(Just another form application renderer)
Stars: ✭ 107 (-13.01%)
Mutual labels:  form
React Controlled Form
Flexible, Modular & Controlled Forms for React and Redux
Stars: ✭ 121 (-1.63%)
Mutual labels:  form
Vue Formulate
⚡️ The easiest way to build forms with Vue.
Stars: ✭ 1,947 (+1482.93%)
Mutual labels:  form
Bootstrap Validate
A simple Form Validation Library for Bootstrap 3 and Bootstrap 4 not depending on jQuery.
Stars: ✭ 112 (-8.94%)
Mutual labels:  form

project logo


MIT commitizen PRs styled with prettier All Contributors ngneat spectator

A flexible and unopinionated edit in place library for Angular applications

Edit in place is a complete solution for switching modes between static content and an editable control that allows editing it.

Following open/closed principle, the library focuses on the switch mechanism, giving you full control of the data you want to update and the content you want to display and how to edit it.

alt-text

Demo

Features

  • ✅ Fully customizable
  • ✅ Manual trigger support
  • ✅ Reactive Forms support
  • ✅ Multiple Forms support

Installation

ng add @ngneat/edit-in-place

Usage

Add the EditableModule to your AppModule.

import { EditableModule } from '@ngneat/edit-in-place';

@NgModule({
  declarations: [AppComponent],
  imports: [EditableModule],
  bootstrap: [AppComponent]
})
export class AppModule {}

Now you can use the <editable> component:

@Component({
  template: `
    <editable (save)="update()" (cancel)="cancel()">
      <ng-template viewMode>{{ value }}</ng-template>

      <ng-template editMode>
        <input editableOnEnter editableOnEscape [formControl]="control" />
      </ng-template>
    </editable>
  `
})
class MyComponent {
  value = 'foo';
  control = new FormControl(this.value);

  update() {
    this.value = this.control.value;
  }

  cancel() {
    this.control.setValue(this.value);
  }
}

For more complex examples, check out the playground.

Changing the Active Mode

Click on the viewMode template to switch it to editMode or click outside the editable component to switch back to viewMode.

You can customize the switch trigger which set to click by default by providing a MouseEvent type:

<editable openBindingEvent="dblclick"
          closeBindingEvent="dblclick">
    ...
</editable>

You can also set this value globally by providing it in the EDITABLE_CONFIG provider:

@NgModule({
  ...
  providers: [
    {
      provide: EDITABLE_CONFIG, 
      useValue: {
        openBindingEvent: 'dblclick',
        closeBindingEvent: 'dblclick',
      } as EditableConfig
    }
  ]
})
export class AppModule {}

Handle Events Manually

You can use the editableOnUpdate and editableOnCancel directives to trigger the update or the reset of the value on chosen elements.

<editable (save)="updateField()" (cancel)="resetField()">
  <ng-template viewMode>...</ng-template>

  <ng-template editMode>
    <input formControlName="name">
    <button editableOnSave>Save</button>
    <button editableOnCancel>Cancel</button>    
  </ng-template>
</editable>

Track event changes

You can use the modeChange event to know what is the state of a given EditableComponent.

<editable (modeChange)="doWhatever()">
  <ng-template viewMode>...</ng-template>

  <ng-template editMode>
    <input formControlName="name">
    <button editableOnSave>Save</button>
    <button editableOnCancel>Cancel</button>    
  </ng-template>
</editable>

Handle Focus

As a focusable form tag might be nested or custom, it isn't focused by default when the editMode is displayed.

To make it focusable, you can add the editableFocus directive on the input:

<editable>

  <ng-template viewMode>
    ... 
  </ng-template>

  <ng-template editMode>
    <input editableFocusable formControlName="name">   
  </ng-template>
</editable>

Events

Add the (save) event binding to handle the update of the content.

<editable (save)="updateField()">
   ...
</editable>

The following actions will trigger this event:

  • editableOnEnter directive
  • editableOnSave directive
  • closeBindingEvent @Input() MouseEvent

Optionally you can add the (cancel) event binding to handle the reset of the value of a formControl:

<editable (cancel)="resetField()">
  ...
</editable>

The following actions will trigger this event:

  • editableCancel directive
  • editableOnEscape directive

Inputs

@Input Type Description Default
openBindingEvent string The MouseEvent type to display the editMode click
closeBindingEvent string The MouseEvent type to display the viewMode click

Outputs

@Output Type Description
save void triggered by the editableOnSave and editableOnEnter directives and the MouseEvent on closeBindingEvent @Input
cancel void triggered by the editableCancel and editableOnEscape directives
modeChange edit or view triggered when the mode changes

Directives

editableFocusable

Focus the host element when switching to editMode (for nested inputs).

editableOnEnter

Listen to keyup enter to switch to viewMode and update the value of the viewMode host element.

editableOnEscape

Listen to keyup escape to switch to viewMode without updating the value of the viewMode host element.

editableOnSave

Listen to a MouseEvent on ths host element in order to switch to viewMode and udpate the value of the content of the viewMode*host element.

@Input Type Description Default
saveEvent string The MouseEvent type used to trigger the @Output() save click

editableOnCancel

Listen to a MouseEvent on ths host element in order to trigger to switch to viewMode without updating the value of the viewMode host element.

@Input Type Description Default
cancelEvent string The MouseEvent type used to trigger the @Output() cancel click

Multiple Forms Usage

edit-in-place also supports switching between modes for multiple components at once.

Add the editableGroup directive on a parent html tag of your editable components:

<section editableGroup>
  <editable></editable>
  <editable></editable>
  <editable></editable>
</section>

Changing the Active Mode

Unlike using a single editable component, an editableGroup doesn't support MouseEvent events on the component to switch modes.

You can switch modes by using dedicated directives on html button tag to switch mode for the whole group:

  • editableGroupEdit to switch to editMode
  • editableGroupSave to save the value of each form tag and switch to viewMode
  • editableGroupCancel to switch to viewMode without saving the value of each form tag
<section editableGroup>
  <button editableGroupEdit>Edit</button>
  <button editableGroupSave>Save</button>
  <button editableGroupCancel>Cancel</button>
  <editable></editable>
  <editable></editable>
  <editable></editable>
</section>

Add the (editableModeChange) event binding to keep track of the active mode.

It's triggered by the editableGroupEdit, editableGroupSave and editableGroupCancel directives.

<section (editableModeChange)="handleModeChange($event)">
  <editable></editable>
  <editable></editable>
  <editable></editable>
</section>

Add the (save) event binding to handle the update of the group.
It's triggered by the editableGroupSave directive:

<section (save)="updateGroup()">
  <editable></editable>
  <editable></editable>
  <editable></editable>
</section>

Optionally you can add the (cancel) event binding to handle the reset of the value of the group.

It's triggered by the editableGroupCancel:

<section (cancel)="cancelUpdate()">
  <editable></editable>
  <editable></editable>
  <editable></editable>
</section>

Directives

editableGroup

Overcharges the behavior of children editable Components to work as one entity.

@Output Type Description
save void triggered by the editableGroupSave directive
cancel void triggered by the editableGroupCancel directive
editableModeChange 'view' or 'edit' triggered by the editableGroupEdit, editableGroupSave and editableGroupCancel directives when switching modes

editableGroupEdit

Listen to a click MouseEvent to switch to editMode.

editableGroupSave

Listen to a click MouseEvent to switch to viewMode and update the value of the group.

editableGroupCancel

Listen to a click MouseEvent to switch to viewMode without updating the value of the group.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Gérôme Grignon

💻 📖 🤔

Netanel Basal

📝 📖 🤔

Itay Oded

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Logo made by Freepik from www.flaticon.com

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].