Skip to content

Commit

Permalink
Detect text changes via paste/cut/delete shortcuts in input fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tkleinke committed Dec 20, 2024
1 parent 50a327c commit 9c7e42f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ export class IdentifierComponent implements OnChanges {
}


public update(value: string) {
public update() {

if (value === '') {
if (this.identifierBody === '') {
delete this.fieldContainer[this.fieldName];
} else {
this.fieldContainer[this.fieldName] = this.identifierPrefix
? this.identifierPrefix + value
: value;
? this.identifierPrefix + this.identifierBody
: this.identifierBody;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[class.focused]="focused">{{identifierPrefix}}</span>
<input #inputField
[(ngModel)]="identifierBody"
(keyup)="update($event.target.value)"
(input)="update()"
(focus)="focused = true"
(blur)="focused = false"
class="form-control"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Component, Input } from '@angular/core';

@Component({
selector: 'form-field-simple-input',
template: `<input [(ngModel)]="fieldContainer[fieldName]" (keyup)="deleteIfEmpty($event.target.value)"
template: `<input [(ngModel)]="fieldContainer[fieldName]" (input)="deleteIfEmpty()"
class="form-control">`
})

Expand All @@ -18,8 +18,8 @@ export class SimpleInputComponent {
@Input() fieldName: string;


public deleteIfEmpty(value: string) {
public deleteIfEmpty() {

if (value === '') delete this.fieldContainer[this.fieldName];
if (this.fieldContainer[this.fieldName] === '') delete this.fieldContainer[this.fieldName];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
<input *ngIf="!multiLine" #inputField [(ngModel)]="selectedText"
[class.focused]="focused"
[class.with-tabs]="hasTabs()"
(keyup)="onChanges($event.target.value)"
(input)="onChanges($event.target.value)"
(focus)="focused = true"
(blur)="onBlur()"
class="form-control">
<textarea *ngIf="multiLine" #inputField [(ngModel)]="selectedText"
[class.focused]="focused"
[class.with-tabs]="hasTabs()"
(keyup)="onChanges($event.target.value)"
(input)="onChanges($event.target.value)"
(focus)="focused = true"
(blur)="onBlur()"
class="form-control"></textarea>
Expand Down

0 comments on commit 9c7e42f

Please sign in to comment.