-
-
+
+
diff --git a/lib/core/form/components/start-form.component.ts b/lib/core/form/components/start-form.component.ts
index 5fa62f021f..2c190330a9 100644
--- a/lib/core/form/components/start-form.component.ts
+++ b/lib/core/form/components/start-form.component.ts
@@ -15,30 +15,26 @@
* limitations under the License.
*/
-import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild, ViewEncapsulation, OnDestroy } from '@angular/core';
+import {
+ Component,
+ ElementRef,
+ EventEmitter,
+ Input,
+ OnChanges,
+ OnInit,
+ Output,
+ SimpleChanges,
+ ViewChild,
+ ViewEncapsulation,
+ OnDestroy
+} from '@angular/core';
import { FormService } from './../services/form.service';
import { WidgetVisibilityService } from './../services/widget-visibility.service';
import { FormComponent } from './form.component';
import { ContentLinkModel } from './widgets/core/content-link.model';
import { FormOutcomeModel } from './widgets/core/index';
-import { Subscription } from 'rxjs';
+import { ValidateFormEvent } from './../events/validate-form.event';
-/**
- * Displays the start form for a named process definition, which can be used to retrieve values to start a new process.
- *
- * After the form has been completed the form values are available from the attribute component.form.values and
- * component.form.isValid (boolean) can be used to check the if the form is valid or not. Both of these properties are
- * updated as the user types into the form.
- *
- * @Input
- * {processDefinitionId} string: The process definition ID
- * {showOutcomeButtons} boolean: Whether form outcome buttons should be shown, this is now always active to show form outcomes
- * @Output
- * {formLoaded} EventEmitter - This event is fired when the form is loaded, it pass all the value in the form.
- * {formSaved} EventEmitter - This event is fired when the form is saved, it pass all the value in the form.
- * {formCompleted} EventEmitter - This event is fired when the form is completed, it pass all the value in the form.
- *
- */
@Component({
selector: 'adf-start-form',
templateUrl: './start-form.component.html',
@@ -47,8 +43,6 @@ import { Subscription } from 'rxjs';
})
export class StartFormComponent extends FormComponent implements OnChanges, OnInit, OnDestroy {
- private subscriptions: Subscription[] = [];
-
/** Definition ID of the process to start. */
@Input()
processDefinitionId: string;
@@ -90,6 +84,11 @@ export class StartFormComponent extends FormComponent implements OnChanges, OnIn
this.subscriptions.push(
this.formService.formContentClicked.subscribe(content => {
this.formContentClicked.emit(content);
+ }),
+ this.formService.validateForm.subscribe((validateFormEvent: ValidateFormEvent) => {
+ if (validateFormEvent.errorsField.length > 0) {
+ this.formError.next(validateFormEvent.errorsField);
+ }
})
);
}
@@ -155,8 +154,8 @@ export class StartFormComponent extends FormComponent implements OnChanges, OnIn
/** @override */
isOutcomeButtonVisible(outcome: FormOutcomeModel, isFormReadOnly: boolean): boolean {
- if (outcome && outcome.isSystem && ( outcome.name === FormOutcomeModel.SAVE_ACTION ||
- outcome.name === FormOutcomeModel.COMPLETE_ACTION )) {
+ if (outcome && outcome.isSystem && (outcome.name === FormOutcomeModel.SAVE_ACTION ||
+ outcome.name === FormOutcomeModel.COMPLETE_ACTION)) {
return false;
} else if (outcome && outcome.name === FormOutcomeModel.START_PROCESS_ACTION) {
return true;
diff --git a/lib/core/form/components/widgets/container/container.widget.html b/lib/core/form/components/widgets/container/container.widget.html
index 4aee462184..3260c8f25c 100644
--- a/lib/core/form/components/widgets/container/container.widget.html
+++ b/lib/core/form/components/widgets/container/container.widget.html
@@ -13,7 +13,7 @@
-
+
diff --git a/lib/core/form/components/widgets/core/form.model.spec.ts b/lib/core/form/components/widgets/core/form.model.spec.ts
index 9befcaffee..6e91f58e7d 100644
--- a/lib/core/form/components/widgets/core/form.model.spec.ts
+++ b/lib/core/form/components/widgets/core/form.model.spec.ts
@@ -271,27 +271,6 @@ describe('FormModel', () => {
form.validateField(field);
});
- it('should skip form validation when default behaviour prevented', () => {
- const form = new FormModel({}, null, false, formService);
-
- let prevented = false;
-
- formService.validateForm.subscribe((event: ValidateFormEvent) => {
- event.isValid = false;
- event.preventDefault();
- prevented = true;
- });
-
- const field = jasmine.createSpyObj('FormFieldModel', ['validate']);
- spyOn(form, 'getFormFields').and.returnValue([field]);
-
- form.validateForm();
-
- expect(prevented).toBeTruthy();
- expect(form.isValid).toBeFalsy();
- expect(field.validate).not.toHaveBeenCalled();
- });
-
it('should skip field validation when default behaviour prevented', () => {
const form = new FormModel({}, null, false, formService);
diff --git a/lib/core/form/components/widgets/core/form.model.ts b/lib/core/form/components/widgets/core/form.model.ts
index ab63af27a6..2ad7009110 100644
--- a/lib/core/form/components/widgets/core/form.model.ts
+++ b/lib/core/form/components/widgets/core/form.model.ts
@@ -15,9 +15,11 @@
* limitations under the License.
*/
- /* tslint:disable:component-selector */
+/* tslint:disable:component-selector */
-import { FormFieldEvent, ValidateFormEvent, ValidateFormFieldEvent } from './../../../events/index';
+import { FormFieldEvent } from './../../../events/form-field.event';
+import { ValidateFormFieldEvent } from './../../../events/validate-form-field.event';
+import { ValidateFormEvent } from './../../../events/validate-form.event';
import { FormService } from './../../../services/form.service';
import { ContainerModel } from './container.model';
import { FormFieldTemplates } from './form-field-templates';
@@ -120,9 +122,21 @@ export class FormModel {
}
if (json.fields) {
- let saveOutcome = new FormOutcomeModel(this, { id: FormModel.SAVE_OUTCOME, name: 'Save', isSystem: true });
- let completeOutcome = new FormOutcomeModel(this, { id: FormModel.COMPLETE_OUTCOME, name: 'Complete', isSystem: true });
- let startProcessOutcome = new FormOutcomeModel(this, { id: FormModel.START_PROCESS_OUTCOME, name: 'Start Process', isSystem: true });
+ let saveOutcome = new FormOutcomeModel(this, {
+ id: FormModel.SAVE_OUTCOME,
+ name: 'Save',
+ isSystem: true
+ });
+ let completeOutcome = new FormOutcomeModel(this, {
+ id: FormModel.COMPLETE_OUTCOME,
+ name: 'Complete',
+ isSystem: true
+ });
+ let startProcessOutcome = new FormOutcomeModel(this, {
+ id: FormModel.START_PROCESS_OUTCOME,
+ name: 'Start Process',
+ isSystem: true
+ });
let customOutcomes = (json.outcomes || []).map(obj => new FormOutcomeModel(this, obj));
@@ -176,27 +190,27 @@ export class FormModel {
* @memberof FormModel
*/
validateForm(): void {
- const validateFormEvent = new ValidateFormEvent(this);
+ const validateFormEvent: any = new ValidateFormEvent(this);
+
+ let errorsField: FormFieldModel[] = [];
+
+ let fields = this.getFormFields();
+ for (let i = 0; i < fields.length; i++) {
+ if (!fields[i].validate()) {
+ errorsField.push(fields[i]);
+ }
+ }
+
+ if (errorsField.length > 0) {
+ this._isValid = false;
+ }
if (this.formService) {
+ validateFormEvent.isValid = this._isValid;
+ validateFormEvent.errorsField = errorsField;
this.formService.validateForm.next(validateFormEvent);
}
- this._isValid = validateFormEvent.isValid;
-
- if (validateFormEvent.defaultPrevented) {
- return;
- }
-
- if (validateFormEvent.isValid) {
- let fields = this.getFormFields();
- for (let i = 0; i < fields.length; i++) {
- if (!fields[i].validate()) {
- this._isValid = false;
- return;
- }
- }
- }
}
/**
@@ -227,8 +241,8 @@ export class FormModel {
if (!field.validate()) {
this._isValid = false;
- return;
}
+
this.validateForm();
}
diff --git a/lib/core/form/components/widgets/tabs/tabs.widget.html b/lib/core/form/components/widgets/tabs/tabs.widget.html
index e71d0d1baf..6e109f87ee 100644
--- a/lib/core/form/components/widgets/tabs/tabs.widget.html
+++ b/lib/core/form/components/widgets/tabs/tabs.widget.html
@@ -2,7 +2,7 @@