added metadata form validation
This commit is contained in:
parent
5f3dabb8b7
commit
5c48a6f4e7
3 changed files with 65 additions and 10 deletions
|
|
@ -1,7 +1,25 @@
|
||||||
<div class="metadata-form-container">
|
<div class="metadata-form-container">
|
||||||
<div>{{ metadata().name }}</div>
|
@if (!editing()) {
|
||||||
|
<div>{{ metadata().name }}</div>
|
||||||
|
|
||||||
<button matIconButton>
|
<button matIconButton (click)="editing.set(true)">
|
||||||
<mat-icon>edit</mat-icon>
|
<mat-icon>edit</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
|
} @else {
|
||||||
|
<div class="metadata-edit">
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<input type="text" matInput [(ngModel)]="name">
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<div class="metadata-edit-buttons">
|
||||||
|
<button matIconButton (click)="reset()">
|
||||||
|
<mat-icon>undo</mat-icon>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button matIconButton (click)="saveMetaData()" [disabled]="!nameValid()">
|
||||||
|
<mat-icon>save</mat-icon>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -3,3 +3,14 @@
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.metadata-edit {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
|
||||||
|
.metadata-edit-buttons {
|
||||||
|
padding-top: 0.5rem;
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
import {Component, input, output, signal} from '@angular/core';
|
import { Component, computed, input, model, OnInit, output, signal } from '@angular/core';
|
||||||
import { MatCardModule } from '@angular/material/card';
|
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import { MatIconModule } from '@angular/material/icon';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { MatFormField, MatInput } from '@angular/material/input';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
|
||||||
interface MetaData {
|
interface MetaData {
|
||||||
id: string;
|
id: string;
|
||||||
|
|
@ -11,17 +12,42 @@ interface MetaData {
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-metadata-form',
|
selector: 'app-metadata-form',
|
||||||
imports: [
|
imports: [
|
||||||
MatCardModule,
|
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatButtonModule
|
MatButtonModule,
|
||||||
|
MatFormField,
|
||||||
|
MatInput,
|
||||||
|
FormsModule
|
||||||
],
|
],
|
||||||
templateUrl: './metadata-form.component.html',
|
templateUrl: './metadata-form.component.html',
|
||||||
styleUrl: './metadata-form.component.scss'
|
styleUrl: './metadata-form.component.scss'
|
||||||
})
|
})
|
||||||
export class MetadataFormComponent {
|
export class MetadataFormComponent implements OnInit {
|
||||||
public metadata = input.required<MetaData>();
|
public metadata = input.required<MetaData>();
|
||||||
|
|
||||||
public newMetaData = output<MetaData>();
|
public newMetaData = output<MetaData>();
|
||||||
|
|
||||||
|
public name = model('');
|
||||||
|
public nameValid = computed(() => {
|
||||||
|
const existingName = this.metadata().name;
|
||||||
|
const newName = this.name();
|
||||||
|
|
||||||
|
return !!newName && newName !== existingName;
|
||||||
|
});
|
||||||
public editing = signal(false);
|
public editing = signal(false);
|
||||||
|
|
||||||
|
public ngOnInit(): void {
|
||||||
|
this.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public saveMetaData(): void {
|
||||||
|
this.editing.set(false);
|
||||||
|
this.newMetaData.emit({
|
||||||
|
...this.metadata(),
|
||||||
|
name: this.name()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public reset(): void {
|
||||||
|
this.editing.set(false);
|
||||||
|
this.name.set(this.metadata().name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue