required fields

This commit is contained in:
_Bastler 2021-10-06 12:36:33 +02:00
parent a90cc514f0
commit 33de9c48eb
2 changed files with 10 additions and 5 deletions

View File

@ -31,7 +31,7 @@
</mat-error>
</mat-form-field>
<mat-form-field>
<textarea [mat-autosize] [matAutosizeMinRows]="3" matInput placeholder="{{'submission.text' | i18n}}"
<textarea [mat-autosize] [matAutosizeMinRows]="3" matInput placeholder="{{'submission.text' | i18n}}" [required]="entryType != 'LINK'"
formControlName="text"></textarea>
<mat-error>
{{'submission.text.error' | i18n}}

View File

@ -33,10 +33,15 @@ export class PageSubmission implements OnInit {
this.form.get('entryType').valueChanges.subscribe((value) => {
this.entryType = value;
if (value == 'LINK') {
this.form.get('url').setValidators([ Validators.required ]);
} else {
this.form.get('url').setValidators([ Validators.nullValidator ]);
switch (value) {
case 'LINK':
this.form.get('url').setValidators([ Validators.required ]);
this.form.get('text').setValidators([ Validators.nullValidator ]);
break;
default:
this.form.get('url').setValidators([ Validators.nullValidator ]);
this.form.get('text').setValidators([ Validators.required ]);
break;
}
});