-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca8f646
commit 5795f3c
Showing
11 changed files
with
80 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 18 additions & 1 deletion
19
templates/angular/app/components/common/form/form.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
<p>form works!</p> | ||
<form [formGroup]="formGroup" (ngSubmit)="handleSubmit()"> | ||
@for (field of fields; track field.name) { | ||
<div class="mb-3"> | ||
<label [for]="field.name">{{ field.name }}</label> | ||
<input [id]="field.name" | ||
[type]="field.type" | ||
[formControlName]="field.name" | ||
class="mt-1 w-full px-3 py-2 border rounded" | ||
> | ||
</div> | ||
} | ||
<button | ||
type="submit" | ||
class="px-6 py-2 bg-green-500 text-white font-medium rounded shadow-md hover:bg-green-600" | ||
> | ||
Submit | ||
</button> | ||
</form> |
28 changes: 25 additions & 3 deletions
28
templates/angular/app/components/common/form/form.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
import { Component } from '@angular/core'; | ||
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; | ||
import {FormControl, FormGroup, ReactiveFormsModule} from "@angular/forms"; | ||
|
||
@Component({ | ||
selector: 'app-form', | ||
standalone: true, | ||
imports: [], | ||
imports: [ | ||
ReactiveFormsModule | ||
], | ||
templateUrl: './form.component.html', | ||
}) | ||
export class FormComponent { | ||
export class FormComponent implements OnInit { | ||
@Input() fields: Array<{ name: string; type: string }> = []; | ||
@Output() submit = new EventEmitter | ||
public formGroup: FormGroup = new FormGroup<any>({}) | ||
|
||
ngOnInit() { | ||
this.formGroup = this.createFormGroup() | ||
} | ||
|
||
createFormGroup() { | ||
const group: { [key: string]: FormControl<string | null> } = {} | ||
|
||
this.fields.forEach(field => { | ||
group[field.name] = new FormControl('') | ||
}) | ||
return new FormGroup(group) | ||
} | ||
|
||
handleSubmit() { | ||
this.submit.emit(this.formGroup.value) | ||
} | ||
} |
26 changes: 5 additions & 21 deletions
26
templates/angular/app/components/foo/create/create.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,14 @@ | ||
<div class="container mx-auto px-4 max-w-2xl mt-4"> | ||
<div class="flex items-center justify-between"> | ||
<a [routerLink]="['/heroes']" | ||
<a [routerLink]="['/{{lc}}']" | ||
class="text-blue-600 hover:text-blue-800"> | ||
Back to list {{lc}} | ||
Back to list | ||
</a> | ||
</div> | ||
@if (isLoading()) { | ||
<div class="bg-blue-100 rounded py-4 px-4 text-blue-700 text-sm">Loading ...</div> | ||
<div class="bg-blue-100 rounded py-4 px-4 text-blue-700 text-sm">Loading ...</div> | ||
} @else { | ||
<h1 class="text-3xl my-4">Create</h1> | ||
|
||
<form (ngSubmit)="onSubmit($event)"> | ||
<div class="mb-3"> | ||
<label for="name"> name</label> | ||
<input id="name" | ||
class="mt-1 w-full px-3 py-2 border rounded" | ||
[formControl]="input" | ||
> | ||
</div> | ||
|
||
<button | ||
type="submit" | ||
class="px-6 py-2 bg-green-500 text-white font-medium rounded shadow-md hover:bg-green-600" | ||
> | ||
Submit | ||
</button> | ||
</form> | ||
<h1 class="text-3xl my-4">Create</h1> | ||
<app-form [fields]="{{{formType}}}" (submit)="onSubmit($event)"/> | ||
} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters