64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
|
|
import {Component, OnInit} from '@angular/core';
|
||
|
|
import {FormsComponent} from '../forms.component';
|
||
|
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
||
|
|
import {AppealsService} from '../../../api';
|
||
|
|
|
||
|
|
@Component({
|
||
|
|
selector: 'app-appeal',
|
||
|
|
imports: [
|
||
|
|
FormsComponent
|
||
|
|
],
|
||
|
|
templateUrl: './appeal.component.html',
|
||
|
|
styleUrl: './appeal.component.scss'
|
||
|
|
})
|
||
|
|
export class AppealComponent implements OnInit {
|
||
|
|
|
||
|
|
public form: FormGroup | undefined;
|
||
|
|
|
||
|
|
constructor(private fb: FormBuilder, private appealApi: AppealsService) {
|
||
|
|
}
|
||
|
|
|
||
|
|
ngOnInit() {
|
||
|
|
this.initForm()
|
||
|
|
}
|
||
|
|
|
||
|
|
private initForm() {
|
||
|
|
this.form = this.fb.group({
|
||
|
|
name: ['', [Validators.required]],
|
||
|
|
punishmentId: ['', [Validators.required]],
|
||
|
|
email: ['', [Validators.required, Validators.email]],
|
||
|
|
message: ['', [Validators.required, Validators.minLength(10)]]
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
public onSubmit() {
|
||
|
|
if (this.form === undefined) {
|
||
|
|
console.error('Form is undefined');
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if (this.form.valid) {
|
||
|
|
console.log('Form submitted:', this.form.value);
|
||
|
|
// Process form submission here
|
||
|
|
} else {
|
||
|
|
// Mark all fields as touched to trigger validation display
|
||
|
|
Object.keys(this.form.controls).forEach(field => {
|
||
|
|
const control = this.form!.get(field);
|
||
|
|
if (!(control instanceof FormGroup)) {
|
||
|
|
console.error('Control [' + control + '] is not a FormGroup');
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
control.markAsTouched({onlySelf: true});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private sendForm(validForm: FormGroup) {
|
||
|
|
// const appeal: MinecraftAppeal = {
|
||
|
|
//
|
||
|
|
// }
|
||
|
|
// this.appealApi.submitMinecraftAppeal()
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|