Fix not being able to save settings in the general tab Fixes #3426

This commit is contained in:
Amelia 2025-04-18 20:57:12 +02:00
parent d3f8a503c2
commit d1dce9d9f3
No known key found for this signature in database
GPG key ID: D6D0ECE365407EAA
2 changed files with 18 additions and 3 deletions

View file

@ -75,7 +75,7 @@
@if(settingsForm.dirty || !settingsForm.untouched) { @if(settingsForm.dirty || !settingsForm.untouched) {
<div id="ipaddresses-validations" class="invalid-feedback"> <div id="ipaddresses-validations" class="invalid-feedback">
@if (formControl.errors?.pattern) { @if (formControl.errors?.emptyOrPattern) {
<div>{{t('ip-address-validation')}}</div> <div>{{t('ip-address-validation')}}</div>
} }
</div> </div>

View file

@ -1,5 +1,5 @@
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, inject, OnInit} from '@angular/core'; import {ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, inject, OnInit} from '@angular/core';
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms'; import {FormControl, FormGroup, ReactiveFormsModule, ValidatorFn, Validators} from '@angular/forms';
import {ToastrService} from 'ngx-toastr'; import {ToastrService} from 'ngx-toastr';
import {take} from 'rxjs/operators'; import {take} from 'rxjs/operators';
import {ServerService} from 'src/app/_services/server.service'; import {ServerService} from 'src/app/_services/server.service';
@ -62,7 +62,7 @@ export class ManageSettingsComponent implements OnInit {
this.settingsForm.addControl('taskScan', new FormControl(this.serverSettings.taskScan, [Validators.required])); this.settingsForm.addControl('taskScan', new FormControl(this.serverSettings.taskScan, [Validators.required]));
this.settingsForm.addControl('taskBackup', new FormControl(this.serverSettings.taskBackup, [Validators.required])); this.settingsForm.addControl('taskBackup', new FormControl(this.serverSettings.taskBackup, [Validators.required]));
this.settingsForm.addControl('taskCleanup', new FormControl(this.serverSettings.taskCleanup, [Validators.required])); this.settingsForm.addControl('taskCleanup', new FormControl(this.serverSettings.taskCleanup, [Validators.required]));
this.settingsForm.addControl('ipAddresses', new FormControl(this.serverSettings.ipAddresses, [Validators.required, Validators.pattern(ValidIpAddress)])); this.settingsForm.addControl('ipAddresses', new FormControl(this.serverSettings.ipAddresses, [this.emptyOrPattern(ValidIpAddress)]));
this.settingsForm.addControl('port', new FormControl(this.serverSettings.port, [Validators.required])); this.settingsForm.addControl('port', new FormControl(this.serverSettings.port, [Validators.required]));
this.settingsForm.addControl('loggingLevel', new FormControl(this.serverSettings.loggingLevel, [Validators.required])); this.settingsForm.addControl('loggingLevel', new FormControl(this.serverSettings.loggingLevel, [Validators.required]));
this.settingsForm.addControl('allowStatCollection', new FormControl(this.serverSettings.allowStatCollection, [Validators.required])); this.settingsForm.addControl('allowStatCollection', new FormControl(this.serverSettings.allowStatCollection, [Validators.required]));
@ -186,4 +186,19 @@ export class ManageSettingsComponent implements OnInit {
console.error('error: ', err); console.error('error: ', err);
}); });
} }
emptyOrPattern(pattern: RegExp): ValidatorFn {
return (control) => {
if (!control.value || control.value.length === 0) {
return null;
}
if (pattern.test(control.value)) {
return null;
}
return { 'emptyOrPattern': { 'requiredPattern': pattern.toString(), 'actualValue': control.value } };
}
}
} }