Add buttons to list field
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.row-wrapper {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,17 +18,34 @@ import {
|
|||||||
selector: 'app-list-field',
|
selector: 'app-list-field',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule, MatButton, MatIconModule, ProtoFieldComponent],
|
imports: [CommonModule, MatButton, MatIconModule, ProtoFieldComponent],
|
||||||
template: ` @for(value of values(); track values()) {
|
template: ` @for(value of values(); track $index) {
|
||||||
<app-proto-field
|
<div class="row-wrapper">
|
||||||
[configuration]="configuration().subConfiguration"
|
<app-proto-field
|
||||||
[value]="value"
|
[configuration]="configuration().subConfiguration"
|
||||||
></app-proto-field>
|
[value]="value"
|
||||||
|
></app-proto-field>
|
||||||
|
<button mat-icon-button (click)="remove($index)">
|
||||||
|
<mat-icon>remove</mat-icon>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
<button mat-icon-button><mat-icon>add</mat-icon></button>`,
|
<button mat-icon-button (click)="add()"><mat-icon>add</mat-icon></button>`,
|
||||||
styleUrl: './list-field.component.scss',
|
styleUrl: './list-field.component.scss',
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
})
|
})
|
||||||
export class ListFieldComponent {
|
export class ListFieldComponent {
|
||||||
configuration = input.required<ListMessage>();
|
configuration = input.required<ListMessage>();
|
||||||
values = model<any[]>();
|
values = model<any[]>();
|
||||||
|
|
||||||
|
add() {
|
||||||
|
const newValues = this.values();
|
||||||
|
newValues?.push(null);
|
||||||
|
this.values.set(newValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(index: number) {
|
||||||
|
const newValues = this.values();
|
||||||
|
newValues?.splice(index, 1);
|
||||||
|
this.values.set(newValues);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user