# vin-content-editable

> By default angular forms only support HTML input element. If someone in their project has to use an element with `contenteditable=true`, in that case they do not any choice except write code for checking validation and other form state like touched or pri

Latest version **2.0.0** (published 2020-09-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install vin-content-editable
pnpm add vin-content-editable
yarn add vin-content-editable
bun add vin-content-editable
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-09-26 |
| First published | 2019-12-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 127.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Vinit Tomar |
| Maintainers | vinittomar |
| Keywords | ng-content-editable, vin-content-editable, mat-content-editable, angular, content editable, content, editabled, generic-toggle, toggle, ng |

## Links

- npm: https://www.npmjs.com/package/vin-content-editable
- Repository: https://github.com/VinitTomar/vin-content-editable
- Homepage: https://github.com/VinitTomar/vin-content-editable#readme
- Issues: https://github.com/VinitTomar/vin-content-editable/issues
- npm.io page: https://npm.io/package/vin-content-editable

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.0.0

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2020-09-26
- 1.2.8 — 2020-04-06
- 1.2.7 — 2020-04-06
- 1.2.6 — 2020-03-12
- 1.2.5 — 2020-02-23
- 1.2.4 — 2020-02-02
- 1.2.3 — 2020-02-02
- 1.2.2 — 2020-02-02
- 1.2.1 — 2020-02-02
- 1.2.0 — 2020-02-02
- 1.1.1 — 2020-01-05
- 1.1.0 — 2020-01-05
- 1.0.3 — 2019-12-15
- 1.0.2 — 2019-12-15
- 1.0.1 — 2019-12-01
- … 3 more at https://npm.io/package/vin-content-editable/versions

## README

# vinContentEditable

By default angular forms only support HTML input element. If someone in their project has to use an element with `contenteditable=true`, in that case they do not any choice except write code for checking validation and other form state like touched or pristien etc, by themselves, which is very error prone.

To overcome this issue, I have created this package `vinContentEditable`. This package has two directives.

1. vinContentEditable: used for adding support for `contenteditable=true` with angular forms.
2. matContentEditableInput: used for adding support for [angular material form field](https://material.angular.io/components/form-field/overview).

## Installation

npm install --save vin-content-editable.

For Angular 10 use version 2.0.x

## Usage

1. Import `VinContentEditableModule` in the component module where we want to use generict toggle.
```
  import { VinContentEditableModule } from 'vin-content-editable';

  @NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    VinContentEditableModule,
    FormsModule,
    ReactiveFormsModule,
  ],
  providers: [],
  bootstrap: [AppComponent],

})
export class AppModule { }
```

2. Use `vinContentEditable` directive for angular forms and `matContentEditableInput` for material form field on the target HTML element.

```
<div vinContentEditable [formControl]="fc"></div>
```

### For angular material form field

```
<mat-form-field>
  <div vinContentEditable [formControl]="fc" matContentEditableInput placeholder="content editable"></div>
  <mat-error *ngIf="fc.touched && fc.invalid">{{matceErr()}}</mat-error>
  <mat-hint>content editable field</mat-hint>
</mat-form-field>
```

3. Here is the type script file code 

```
  fc = new FormControl('form control', Validators.required);

  constructor() { }

  ngOnInit() {
    this.fc.valueChanges.subscribe(val => {
      console.log({ val })
    });
  }
```

4. This is `optional`. In case of angular material there are very good changes that you design might break. To overcome this issue add below style to `global style sheet` or in the current componet with `::ng-deep`. 

```
.mat-form-field-infix {
    [contenteditable]:first-child {
      margin: 0px;
      outline: 0px;
      min-height: 1.125em;
      line-height: 1.125em;
      display: inline-block;
    }
  }
```

or if you are using scss, you can import style from `@import 'vin-content-editable/mat-content-editable-styles';` and run mixin `mat-content-editable-styles` after your angular material styles.

Thats all you have to do.

If you find any issue please feel free to raise it on github.

### Tip
You can use `innerText` or `innerHTML` to get value from with `vinContentEditable` directive. E.g. 
```
vinContentEditable="innerHTML"
```

## Example
Here is the [Demo](https://stackblitz.com/edit/ng-content-editable)



### Please have a look on these also
1. [NgGenericRadio](https://www.npmjs.com/package/ng-generic-radio)
2. [NgGenericToggle](https://www.npmjs.com/package/ng-generic-toggle)

---
_Source: https://npm.io/package/vin-content-editable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
