diff --git a/src/app/system-wide-alert/alert-form/system-wide-alert-form.component.spec.ts b/src/app/system-wide-alert/alert-form/system-wide-alert-form.component.spec.ts index 5804b469b83..2616b2accf9 100644 --- a/src/app/system-wide-alert/alert-form/system-wide-alert-form.component.spec.ts +++ b/src/app/system-wide-alert/alert-form/system-wide-alert-form.component.spec.ts @@ -311,6 +311,14 @@ describe('SystemWideAlertFormComponent', () => { expect(comp.back).not.toHaveBeenCalled(); }); + it('should not create the new alert when the enable button is clicked on an invalid the form', () => { + spyOn(comp as any, 'handleResponse'); + + comp.formMessage.patchValue(''); + comp.save(); + + expect((comp as any).handleResponse).not.toHaveBeenCalled(); + }); }); describe('back', () => { it('should navigate back to the home page', () => { diff --git a/src/app/system-wide-alert/alert-form/system-wide-alert-form.component.ts b/src/app/system-wide-alert/alert-form/system-wide-alert-form.component.ts index 5a0ab9d3e2f..b30e864fa12 100644 --- a/src/app/system-wide-alert/alert-form/system-wide-alert-form.component.ts +++ b/src/app/system-wide-alert/alert-form/system-wide-alert-form.component.ts @@ -256,11 +256,13 @@ export class SystemWideAlertFormComponent implements OnInit { } else { alert.countdownTo = null; } - if (hasValue(this.currentAlert)) { - const updatedAlert = Object.assign(new SystemWideAlert(), this.currentAlert, alert); - this.handleResponse(this.systemWideAlertDataService.put(updatedAlert), 'system-wide-alert.form.update', navigateToHomePage); - } else { - this.handleResponse(this.systemWideAlertDataService.create(alert), 'system-wide-alert.form.create', navigateToHomePage); + if (this.alertForm.valid) { + if (hasValue(this.currentAlert)) { + const updatedAlert = Object.assign(new SystemWideAlert(), this.currentAlert, alert); + this.handleResponse(this.systemWideAlertDataService.put(updatedAlert), 'system-wide-alert.form.update', navigateToHomePage); + } else { + this.handleResponse(this.systemWideAlertDataService.create(alert), 'system-wide-alert.form.create', navigateToHomePage); + } } }