mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2225] visibility and validation must be done after form is parsed (#2931)
* [ADF-2225] visibility and validation must be done after form is parsed * [ADF-2225] remove fdescribe * [ADF-2225] fixed broken test * [ADF-2225] moved check visibility appended to the main condition * [ADF-2225] added visibility check to new validators
This commit is contained in:
@@ -225,6 +225,17 @@ describe('FormComponent', () => {
|
||||
expect(formComponent.getFormDefinitionByFormId).toHaveBeenCalledWith(formId);
|
||||
});
|
||||
|
||||
it('should refresh visibility when the form is loaded', () => {
|
||||
spyOn(formService, 'getFormDefinitionById').and.returnValue(Observable.of(fakeForm));
|
||||
const formId = '123';
|
||||
|
||||
formComponent.formId = formId;
|
||||
formComponent.loadForm();
|
||||
|
||||
expect(formService.getFormDefinitionById).toHaveBeenCalledWith(formId);
|
||||
expect(visibilityService.refreshVisibility).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should get form definition by form name on load', () => {
|
||||
spyOn(formComponent, 'getFormDefinitionByFormName').and.stub();
|
||||
const formName = '<form>';
|
||||
|
@@ -344,6 +344,7 @@ export class FormComponent implements OnInit, OnChanges {
|
||||
form => {
|
||||
const parsedForm = this.parseForm(form);
|
||||
this.visibilityService.refreshVisibility(parsedForm);
|
||||
parsedForm.validateForm();
|
||||
this.form = parsedForm;
|
||||
this.onFormLoaded(this.form);
|
||||
resolve(this.form);
|
||||
@@ -365,6 +366,8 @@ export class FormComponent implements OnInit, OnChanges {
|
||||
form => {
|
||||
this.formName = form.name;
|
||||
this.form = this.parseForm(form);
|
||||
this.visibilityService.refreshVisibility(this.form);
|
||||
this.form.validateForm();
|
||||
this.onFormLoaded(this.form);
|
||||
},
|
||||
(error) => {
|
||||
@@ -381,6 +384,8 @@ export class FormComponent implements OnInit, OnChanges {
|
||||
this.formService.getFormDefinitionById(id).subscribe(
|
||||
form => {
|
||||
this.form = this.parseForm(form);
|
||||
this.visibilityService.refreshVisibility(this.form);
|
||||
this.form.validateForm();
|
||||
this.onFormLoaded(this.form);
|
||||
},
|
||||
(error) => {
|
||||
|
@@ -39,6 +39,7 @@ describe('ActivitiStartForm', () => {
|
||||
let component: StartFormComponent;
|
||||
let fixture: ComponentFixture<StartFormComponent>;
|
||||
let getStartFormSpy: jasmine.Spy;
|
||||
let visibilityService: WidgetVisibilityService;
|
||||
|
||||
const exampleId1 = 'my:process1';
|
||||
const exampleId2 = 'my:process2';
|
||||
@@ -71,11 +72,11 @@ describe('ActivitiStartForm', () => {
|
||||
fixture = TestBed.createComponent(StartFormComponent);
|
||||
component = fixture.componentInstance;
|
||||
formService = fixture.debugElement.injector.get(FormService);
|
||||
visibilityService = TestBed.get(WidgetVisibilityService);
|
||||
|
||||
getStartFormSpy = spyOn(formService, 'getStartFormDefinition').and.returnValue(Observable.of({
|
||||
processDefinitionName: 'my:process'
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
it('should load start form on change if processDefinitionId defined', () => {
|
||||
@@ -90,6 +91,14 @@ describe('ActivitiStartForm', () => {
|
||||
expect(formService.getStartFormDefinition).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should check visibility when the start form is loaded', () => {
|
||||
spyOn(visibilityService, 'refreshVisibility');
|
||||
component.processDefinitionId = exampleId1;
|
||||
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId2, true) });
|
||||
expect(formService.getStartFormDefinition).toHaveBeenCalled();
|
||||
expect(visibilityService.refreshVisibility).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not load start form when changes notified but no change to processDefinitionId', () => {
|
||||
component.processDefinitionId = exampleId1;
|
||||
component.ngOnChanges({ otherProp: new SimpleChange(exampleId1, exampleId2, true) });
|
||||
|
@@ -120,6 +120,8 @@ export class StartFormComponent extends FormComponent implements OnChanges, OnIn
|
||||
form.processVariables = intance.variables;
|
||||
}
|
||||
this.form = this.parseForm(form);
|
||||
this.visibilityService.refreshVisibility(this.form);
|
||||
this.form.validateForm();
|
||||
this.form.readOnly = this.readOnlyForm;
|
||||
this.onFormLoaded(this.form);
|
||||
},
|
||||
@@ -135,6 +137,8 @@ export class StartFormComponent extends FormComponent implements OnChanges, OnIn
|
||||
form => {
|
||||
this.formName = form.processDefinitionName;
|
||||
this.form = this.parseForm(form);
|
||||
this.visibilityService.refreshVisibility(this.form);
|
||||
this.form.validateForm();
|
||||
this.form.readOnly = this.readOnlyForm;
|
||||
this.onFormLoaded(this.form);
|
||||
},
|
||||
|
@@ -53,7 +53,7 @@ export class RequiredFieldValidator implements FormFieldValidator {
|
||||
}
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
if (this.isSupported(field)) {
|
||||
if (this.isSupported(field) && field.isVisible) {
|
||||
|
||||
if (field.type === FormFieldTypes.DROPDOWN) {
|
||||
if (field.hasEmptyValue && field.emptyOption) {
|
||||
@@ -105,7 +105,7 @@ export class NumberFieldValidator implements FormFieldValidator {
|
||||
}
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
if (this.isSupported(field)) {
|
||||
if (this.isSupported(field) && field.isVisible) {
|
||||
if (field.value === null ||
|
||||
field.value === undefined ||
|
||||
field.value === '') {
|
||||
@@ -147,7 +147,7 @@ export class DateFieldValidator implements FormFieldValidator {
|
||||
}
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
if (this.isSupported(field) && field.value) {
|
||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||
if (DateFieldValidator.isValidDate(field.value, field.dateDisplayFormat)) {
|
||||
return true;
|
||||
}
|
||||
@@ -171,7 +171,7 @@ export class MinDateFieldValidator implements FormFieldValidator {
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
let isValid = true;
|
||||
if (this.isSupported(field) && field.value) {
|
||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||
const dateFormat = field.dateDisplayFormat;
|
||||
|
||||
if (!DateFieldValidator.isValidDate(field.value, dateFormat)) {
|
||||
@@ -219,7 +219,7 @@ export class MaxDateFieldValidator implements FormFieldValidator {
|
||||
}
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
if (this.isSupported(field) && field.value) {
|
||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||
const dateFormat = field.dateDisplayFormat;
|
||||
|
||||
if (!DateFieldValidator.isValidDate(field.value, dateFormat)) {
|
||||
@@ -259,7 +259,7 @@ export class MinDateTimeFieldValidator implements FormFieldValidator {
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
let isValid = true;
|
||||
if (this.isSupported(field) && field.value) {
|
||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||
const dateFormat = field.dateDisplayFormat;
|
||||
|
||||
if (!DateFieldValidator.isValidDate(field.value, dateFormat)) {
|
||||
@@ -306,7 +306,7 @@ export class MaxDateTimeFieldValidator implements FormFieldValidator {
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
let isValid = true;
|
||||
if (this.isSupported(field) && field.value) {
|
||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||
const dateFormat = field.dateDisplayFormat;
|
||||
|
||||
if (!DateFieldValidator.isValidDate(field.value, dateFormat)) {
|
||||
@@ -354,7 +354,7 @@ export class MinLengthFieldValidator implements FormFieldValidator {
|
||||
}
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
if (this.isSupported(field) && field.value) {
|
||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||
if (field.value.length >= field.minLength) {
|
||||
return true;
|
||||
}
|
||||
@@ -380,7 +380,7 @@ export class MaxLengthFieldValidator implements FormFieldValidator {
|
||||
}
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
if (this.isSupported(field) && field.value) {
|
||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||
if (field.value.length <= field.maxLength) {
|
||||
return true;
|
||||
}
|
||||
@@ -406,7 +406,7 @@ export class MinValueFieldValidator implements FormFieldValidator {
|
||||
}
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
if (this.isSupported(field) && field.value) {
|
||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||
let value: number = +field.value;
|
||||
let minValue: number = +field.minValue;
|
||||
|
||||
@@ -436,7 +436,7 @@ export class MaxValueFieldValidator implements FormFieldValidator {
|
||||
}
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
if (this.isSupported(field) && field.value) {
|
||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||
let value: number = +field.value;
|
||||
let maxValue: number = +field.maxValue;
|
||||
|
||||
@@ -465,7 +465,7 @@ export class RegExFieldValidator implements FormFieldValidator {
|
||||
}
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
if (this.isSupported(field) && field.value) {
|
||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||
if (field.value.length > 0 && field.value.match(new RegExp('^' + field.regexPattern + '$'))) {
|
||||
return true;
|
||||
}
|
||||
@@ -508,7 +508,7 @@ export class FixedValueFieldValidator implements FormFieldValidator {
|
||||
}
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
if (this.isSupported(field)) {
|
||||
if (this.isSupported(field) && field.isVisible) {
|
||||
if (this.hasStringValue(field) && this.hasOptions(field) && !this.hasValidNameOrValidId(field)) {
|
||||
field.validationSummary.message = 'FORM.FIELD.VALIDATOR.INVALID_VALUE';
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user