Components/create-modal: add form
This commit is contained in:
parent
8fa6f48b65
commit
b92e54beab
2 changed files with 45 additions and 2 deletions
|
|
@ -3,5 +3,25 @@
|
||||||
<button type="button" class="btn-close" aria-label="Close" (click)="dismiss()"></button>
|
<button type="button" class="btn-close" aria-label="Close" (click)="dismiss()"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<p>Hello</p>
|
<form [formGroup]="newShowForm" (ngSubmit)="formSubmitted(newShowForm)">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Title</label>
|
||||||
|
<input formControlName="title" type="text" class="form-control"/>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Year</label>
|
||||||
|
<input formControlName="year" type="number" class="form-control"/>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Seasons</label>
|
||||||
|
<input formControlName="seasons" type="number" class="form-control"/>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Description</label>
|
||||||
|
<input formControlName="description" type="text" class="form-control"/>
|
||||||
|
</div>
|
||||||
|
<div class="d-grid justify-content-md-end">
|
||||||
|
<button type="submit" class="btn btn-success" [disabled]="newShowForm.invalid">Submit</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,39 @@
|
||||||
import {Component, inject} from '@angular/core';
|
import {Component, inject} from '@angular/core';
|
||||||
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
|
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-create-modal',
|
selector: 'app-create-modal',
|
||||||
imports: [],
|
imports: [
|
||||||
|
ReactiveFormsModule
|
||||||
|
],
|
||||||
templateUrl: './create-modal.component.html',
|
templateUrl: './create-modal.component.html',
|
||||||
styleUrl: './create-modal.component.css'
|
styleUrl: './create-modal.component.css'
|
||||||
})
|
})
|
||||||
export class CreateModalComponent {
|
export class CreateModalComponent {
|
||||||
private activeModal = inject(NgbActiveModal)
|
private activeModal = inject(NgbActiveModal)
|
||||||
|
protected newShowForm: FormGroup
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.newShowForm = new FormGroup({
|
||||||
|
title: new FormControl("", Validators.required),
|
||||||
|
year: new FormControl("", [Validators.required, Validators.min(1900)]),
|
||||||
|
seasons: new FormControl("", [Validators.required, Validators.min(1)]),
|
||||||
|
description: new FormControl("", Validators.required)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
protected dismiss() {
|
protected dismiss() {
|
||||||
this.activeModal.dismiss()
|
this.activeModal.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected formSubmitted(form: FormGroup) {
|
||||||
|
let show: {} = {
|
||||||
|
title: form.get("title")?.value,
|
||||||
|
year: form.get("year")?.value,
|
||||||
|
seasons: form.get("seasons")?.value,
|
||||||
|
description: form.get("description")?.value
|
||||||
|
}
|
||||||
|
console.log(show)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue