Skip to content

Commit b3b3ef8

Browse files
authored
Merge pull request DSpace#2877 from alexandrevryghem/fix-systemwidealert-form-validation_contribute-main
System-wide alert shouldn't be created when the message is empty
2 parents 41eccbb + 03e4990 commit b3b3ef8

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/app/system-wide-alert/alert-form/system-wide-alert-form.component.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,14 @@ describe('SystemWideAlertFormComponent', () => {
311311
expect(comp.back).not.toHaveBeenCalled();
312312

313313
});
314+
it('should not create the new alert when the enable button is clicked on an invalid the form', () => {
315+
spyOn(comp as any, 'handleResponse');
316+
317+
comp.formMessage.patchValue('');
318+
comp.save();
319+
320+
expect((comp as any).handleResponse).not.toHaveBeenCalled();
321+
});
314322
});
315323
describe('back', () => {
316324
it('should navigate back to the home page', () => {

src/app/system-wide-alert/alert-form/system-wide-alert-form.component.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,13 @@ export class SystemWideAlertFormComponent implements OnInit {
256256
} else {
257257
alert.countdownTo = null;
258258
}
259-
if (hasValue(this.currentAlert)) {
260-
const updatedAlert = Object.assign(new SystemWideAlert(), this.currentAlert, alert);
261-
this.handleResponse(this.systemWideAlertDataService.put(updatedAlert), 'system-wide-alert.form.update', navigateToHomePage);
262-
} else {
263-
this.handleResponse(this.systemWideAlertDataService.create(alert), 'system-wide-alert.form.create', navigateToHomePage);
259+
if (this.alertForm.valid) {
260+
if (hasValue(this.currentAlert)) {
261+
const updatedAlert = Object.assign(new SystemWideAlert(), this.currentAlert, alert);
262+
this.handleResponse(this.systemWideAlertDataService.put(updatedAlert), 'system-wide-alert.form.update', navigateToHomePage);
263+
} else {
264+
this.handleResponse(this.systemWideAlertDataService.create(alert), 'system-wide-alert.form.create', navigateToHomePage);
265+
}
264266
}
265267
}
266268

0 commit comments

Comments
 (0)