From 5c48a6f4e762c4a4ef73522a93dc49d385611f70 Mon Sep 17 00:00:00 2001 From: Joe Arndt Date: Thu, 26 Feb 2026 11:22:09 -0600 Subject: [PATCH] added metadata form validation --- .../metadata-form.component.html | 26 +++++++++++-- .../metadata-form.component.scss | 11 ++++++ .../metadata-form/metadata-form.component.ts | 38 ++++++++++++++++--- 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/src/app/components/metadata/metadata-form/metadata-form.component.html b/src/app/components/metadata/metadata-form/metadata-form.component.html index b89bc21..a93b42e 100644 --- a/src/app/components/metadata/metadata-form/metadata-form.component.html +++ b/src/app/components/metadata/metadata-form/metadata-form.component.html @@ -1,7 +1,25 @@
-
{{ metadata().name }}
+ @if (!editing()) { +
{{ metadata().name }}
- + + } @else { + + }
diff --git a/src/app/components/metadata/metadata-form/metadata-form.component.scss b/src/app/components/metadata/metadata-form/metadata-form.component.scss index fc26b52..102e1f0 100644 --- a/src/app/components/metadata/metadata-form/metadata-form.component.scss +++ b/src/app/components/metadata/metadata-form/metadata-form.component.scss @@ -3,3 +3,14 @@ gap: 0.5rem; align-items: center; } + +.metadata-edit { + display: flex; + gap: 0.5rem; + + .metadata-edit-buttons { + padding-top: 0.5rem; + display: flex; + gap: 0.5rem; + } +} diff --git a/src/app/components/metadata/metadata-form/metadata-form.component.ts b/src/app/components/metadata/metadata-form/metadata-form.component.ts index 5cf848f..1be9daa 100644 --- a/src/app/components/metadata/metadata-form/metadata-form.component.ts +++ b/src/app/components/metadata/metadata-form/metadata-form.component.ts @@ -1,7 +1,8 @@ -import {Component, input, output, signal} from '@angular/core'; -import { MatCardModule } from '@angular/material/card'; +import { Component, computed, input, model, OnInit, output, signal } from '@angular/core'; import { MatIconModule } from '@angular/material/icon'; import { MatButtonModule } from '@angular/material/button'; +import { MatFormField, MatInput } from '@angular/material/input'; +import { FormsModule } from '@angular/forms'; interface MetaData { id: string; @@ -11,17 +12,42 @@ interface MetaData { @Component({ selector: 'app-metadata-form', imports: [ - MatCardModule, MatIconModule, - MatButtonModule + MatButtonModule, + MatFormField, + MatInput, + FormsModule ], templateUrl: './metadata-form.component.html', styleUrl: './metadata-form.component.scss' }) -export class MetadataFormComponent { +export class MetadataFormComponent implements OnInit { public metadata = input.required(); - public newMetaData = output(); + public name = model(''); + public nameValid = computed(() => { + const existingName = this.metadata().name; + const newName = this.name(); + + return !!newName && newName !== existingName; + }); 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); + } }