Maurizio Vitale 1fa81962a0
👽 Angular 14 rebase 👽 (#7769)
* fix after rebase

* new release strategy for ng next

Signed-off-by: eromano <eugenioromano16@gmail.com>

* peer dep

Signed-off-by: eromano <eugenioromano16@gmail.com>

* Angular 14

fix unit test and storybook

Signed-off-by: eromano <eugenioromano16@gmail.com>

fix after rebase

Signed-off-by: eromano <eugenioromano16@gmail.com>

update pkg.json

Signed-off-by: eromano <eugenioromano16@gmail.com>

missing dep

Signed-off-by: eromano <eugenioromano16@gmail.com>

Fix mistake and missing code

Dream....build only affected libs

Add utility run commands

* Use nx command to run affected tests

* Fix nx test core

fix content tests

Run unit with watch false

core test fixes

reduce test warnings

Fix process cloud unit

Fix adf unit test

Fix lint process cloud

Disable lint next line

Use right core path

Fix insights unit

fix linting insights

Fix process-services unit

fix the extensions test report

fix test warnings

Fix content unit

Fix bunch of content unit

* Produce an adf alpha of 14

* hopefully fixing the content

* Push back the npm publish

* Remove flaky unit

* Fix linting

* Make the branch as root

* Get rid of angualar13

* Remove the travis depth

* Fixing version for npm

* Enabling cache for unit and build

* Fix scss for core and paths

Copy i18 and asset by using ng-packager

Export the theming alias and fix path

Use ng-package to copy assets process-services-cloud

Use ng-package to copy assets process-services

Use ng-package to copy assets content-services

Use ng-package to copy assets insights

* feat: fix api secondary entry point

* fix storybook rebase

* Move dist under dist/libs from lib/dist

* Fix the webstyle

* Use only necessary nrwl deps and improve lint

* Fix unit for libs

* Convert lint.sh to targets - improve performance

* Use latest of angular

* Align alfresco-js-api

Signed-off-by: eromano <eugenioromano16@gmail.com>
Co-authored-by: eromano <eugenioromano16@gmail.com>
Co-authored-by: Mikolaj Serwicki <mikolaj.serwicki@hyland.com>
Co-authored-by: Tomasz <tomasz.gnyp@hyland.com>
2022-08-25 10:50:30 +01:00

11 KiB

Title, Added, Status, Last reviewed
Title Added Status Last reviewed
Form cloud component v3.2.0 Active 2019-04-12

Form cloud component

Shows a form from Process Services.

Contents

Basic Usage

<adf-cloud-form 
    [appName]="appName"
    [taskId]="taskId"
    [processInstanceId]="processInstanceId">
</adf-cloud-form>

Custom form outcomes template

You can set the custom form outcomes using an <adf-cloud-form-custom-outcomes> element.

<adf-cloud-form .... >

    <adf-cloud-form-custom-outcomes>
        <button mat-button (click)="onCustomOutcome1()">
            Custom-outcome-1
        </button>
        <button mat-button (click)="onCustomOutcome2()">
            Custom-outcome-2
        </button>
        <button mat-button (click)="onCustomOutcome3()">
            Custom-outcome-3
        </button>
    </adf-cloud-form-custom-outcomes>

</adf-cloud-form>

Empty form template

The template defined inside empty-form will be shown when no form definition is found:

<adf-cloud-form .... >

    <div empty-form >
        <h2>Empty form</h2>
    </div>

</adf-cloud-form>

Class members

Properties

Name Type Default value Description
appName string "" App name to fetch corresponding form and values.
appVersion number The application version to use when fetching data
data TaskVariableCloud[] Custom form values map to be used with the rendered form.
disableCompleteButton boolean false If true then the Complete outcome button is shown but it will be disabled.
disableSaveButton boolean false If true then the Save outcome button is shown but will be disabled.
disableStartProcessButton boolean false If true then the Start Process outcome button is shown but it will be disabled.
fieldValidators FormFieldValidator[] FormFieldValidator allow to override the form field validators provided.
form FormModel Underlying form model instance.
formId string Task id to fetch corresponding form and values.
nameNode string Name to assign to the new node where the metadata are stored.
path string Path of the folder where the metadata will be stored.
processInstanceId string ProcessInstanceId id to fetch corresponding form and values.
readOnly boolean false Toggle readonly state of the form. Forces all form widgets to render as readonly if enabled.
showCompleteButton boolean true Toggle rendering of the Complete outcome button.
showRefreshButton boolean true Toggle rendering of the Refresh button.
showSaveButton boolean true Toggle rendering of the Save outcome button.
showTitle boolean true Toggle rendering of the form title.
showValidationIcon boolean true Toggle rendering of the validation icon next to the form title.
taskId string Task id to fetch corresponding form and values.

Events

Name Type Description
error EventEmitter<any> Emitted when any error occurs.
executeOutcome EventEmitter<FormOutcomeEvent> Emitted when any outcome is executed. Default behaviour can be prevented via event.preventDefault().
formCompleted EventEmitter<FormModel> Emitted when the form is submitted with the Complete outcome.
formContentClicked EventEmitter<ContentLinkModel> Emitted when form content is clicked.
formDataRefreshed EventEmitter<FormModel> Emitted when form values are refreshed due to a data property change.
formError EventEmitter<FormFieldModel[]> Emitted when the supplied form values have a validation error.
formLoaded EventEmitter<FormModel> Emitted when the form is loaded or reloaded.
formSaved EventEmitter<FormModel> Emitted when the form is submitted with the Save or custom outcomes.

Details

All formXXX events receive a FormCloudModel instance as their argument:

MyView.component.html

<adf-cloud-form
    [appName]="appName"
    [taskId]="selectedTask?.id"
    [processInstanceId]="selectedTask?.processInstanceId"
    (formSaved)="onFormSaved($event)">
</adf-cloud-form>

MyView.component.ts

onFormSaved(form: FormCloudModel) {
    console.log(form);
}

Displaying a form

There are various ways to display a form. The common scenarios are detailed below.

Displaying a form instance by task id and processInstanceId

<adf-cloud-form 
    [appName]="appName"
    [taskId]="selectedTask?.id"
    [processInstanceId]="selectedTask?.processInstanceId">
</adf-cloud-form>

For an existing Task both the form and its values will be fetched and displayed.

Displaying a form definition by form id

<adf-cloud-form 
    [appName]="appName"
    [formId]="selectedFormDefinition?.id"
    [data]="customData">
</adf-cloud-form>

In this case, only the form definition will be fetched.

Controlling outcome execution behaviour

In unusual circumstances, you may need to take complete control of form outcome execution. You can do this by implementing the executeOutcome event, which is emitted for both system outcomes and custom ones.

Note that by default, the code in your executeOutcome handler is executed before the default behavior but you can switch the default behavior off using event.preventDefault(). You might want to do this, for example, to provide custom form validation or to show a summary of the form validation before it is submitted.

MyView.component.html

<adf-cloud-form
    [appName]="appName"
    [taskId]="selectedTask?.id"
    [processInstanceId]="selectedTask?.processInstanceId"
    executeOutcome="validateForm($event)">
</adf-cloud-form>

MyView.component.ts

import { FormOutcomeEvent } from '@alfresco/adf-core';

export class MyView {

    validateForm(event: FormOutcomeEvent) {
        let outcome = event.outcome;

        // you can also get additional properties of outcomes
        // if you defined them within outcome definition

        if (outcome) {
            let form = outcome.form;
            if (form) {
                // check/update the form here
                event.preventDefault();
            }
        }
    }

}

There are two other functions that can be very useful when you need to control form outcomes:

  • saveTaskForm() - Saves the current form
  • completeTaskForm(outcome?: string) Saves and completes the form with a given outcome name

Field Validators

You can supply a set of validator objects to the form using the fieldValidators property. Each validator implements a check for a particular type of data (eg, a date validator might check that the date in the field falls between 1980 and 2017). ADF supplies a standard set of validators that handle most common cases but you can also implement your own custom validators to replace or extend the set. See the Form Field Validator interface for full details and examples.

Common scenarios

Rendering a form using form definition JSON

See the demo-form file for an example of form definition JSON.

The component below (with the JSON assigned to the formDefinitionJSON property), shows how a form definition is rendered:

@Component({
    selector: 'sample-form',
    template: `<div class="form-container">
                    <adf-cloud-form
                        [form]="form">
                    </adf-cloud-form>
                </div>`
})
export class SampleFormComponent implements OnInit {

    form: FormCloudModel;
    formDefinitionJSON: any;

    constructor(private formService: FormService) {
    }

    ngOnInit() {        
        this.form = this.formService.parseForm(this.formDefinitionJSON);
    }
}

Customizing the styles of form outcome buttons

You can use normal CSS selectors to style the outcome buttons of your form. Every outcome has an CSS id value following a simple pattern:

  adf-cloud-form-OUTCOME_NAME

In the CSS, you can target any outcome ID and change the style as in this example:

#adf-cloud-form-complete {
    background-color: blue !important;
    color: white;
}


#adf-cloud-form-save {
    background-color: green !important;
    color: white;
}

#adf-cloud-form-customoutcome {
    background-color: yellow !important;
    color: white;
}

See also