mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
fixed issue with validation
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div *ngIf="missingParameters.length > 0" class="alert alert-danger validation-error">
|
<div *ngIf="missingParameters.length > 0" class="mt-3 alert alert-danger validation-error">
|
||||||
{{'process.new.parameter.required.missing' | translate}}
|
{{'process.new.parameter.required.missing' | translate}}
|
||||||
<ul>
|
<ul>
|
||||||
<li *ngFor="let missing of missingParameters">{{missing}}</li>
|
<li *ngFor="let missing of missingParameters">{{missing}}</li>
|
||||||
|
@@ -15,7 +15,7 @@ import { TranslateLoaderMock } from '../../shared/mocks/translate-loader.mock';
|
|||||||
import { RequestService } from '../../core/data/request.service';
|
import { RequestService } from '../../core/data/request.service';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
describe('NewProcessComponent', () => {
|
describe('ProcessFormComponent', () => {
|
||||||
let component: ProcessFormComponent;
|
let component: ProcessFormComponent;
|
||||||
let fixture: ComponentFixture<ProcessFormComponent>;
|
let fixture: ComponentFixture<ProcessFormComponent>;
|
||||||
let scriptService;
|
let scriptService;
|
||||||
@@ -80,7 +80,7 @@ describe('NewProcessComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call invoke on the scriptService on submit', () => {
|
it('should call invoke on the scriptService on submit', () => {
|
||||||
component.submitForm({ invalid: false } as any);
|
component.submitForm({ controls: {} } as any);
|
||||||
expect(scriptService.invoke).toHaveBeenCalled();
|
expect(scriptService.invoke).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -85,12 +85,12 @@ export class ProcessFormComponent implements OnInit {
|
|||||||
if (requestEntry.response.isSuccessful) {
|
if (requestEntry.response.isSuccessful) {
|
||||||
const title = this.translationService.get('process.new.notification.success.title');
|
const title = this.translationService.get('process.new.notification.success.title');
|
||||||
const content = this.translationService.get('process.new.notification.success.content');
|
const content = this.translationService.get('process.new.notification.success.content');
|
||||||
this.notificationsService.success(title, content)
|
this.notificationsService.success(title, content);
|
||||||
this.sendBack();
|
this.sendBack();
|
||||||
} else {
|
} else {
|
||||||
const title = this.translationService.get('process.new.notification.error.title');
|
const title = this.translationService.get('process.new.notification.error.title');
|
||||||
const content = this.translationService.get('process.new.notification.error.content');
|
const content = this.translationService.get('process.new.notification.error.content');
|
||||||
this.notificationsService.error(title, content)
|
this.notificationsService.error(title, content);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -115,16 +115,18 @@ export class ProcessFormComponent implements OnInit {
|
|||||||
* @param form The NgForm object to validate
|
* @param form The NgForm object to validate
|
||||||
*/
|
*/
|
||||||
private validateForm(form: NgForm) {
|
private validateForm(form: NgForm) {
|
||||||
if (form.invalid) {
|
let valid = true;
|
||||||
Object.keys(form.controls).forEach((key) => {
|
Object.keys(form.controls).forEach((key) => {
|
||||||
|
if (form.controls[key].invalid) {
|
||||||
form.controls[key].markAsDirty();
|
form.controls[key].markAsDirty();
|
||||||
});
|
valid = false;
|
||||||
return false;
|
}
|
||||||
}
|
});
|
||||||
return true;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private isRequiredMissing() {
|
private isRequiredMissing() {
|
||||||
|
this.missingParameters = [];
|
||||||
const setParams: string[] = this.parameters
|
const setParams: string[] = this.parameters
|
||||||
.map((param) => param.name);
|
.map((param) => param.name);
|
||||||
const requiredParams: ScriptParameter[] = this.selectedScript.parameters.filter((param) => param.mandatory);
|
const requiredParams: ScriptParameter[] = this.selectedScript.parameters.filter((param) => param.mandatory);
|
||||||
|
Reference in New Issue
Block a user