mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-584] [ADF-3561] Validation error summary for error component (#3795)
* emit Forms error * add demo * add documentation remove old form tag deprecated in 1.x fix translation outcome * remove prevent default validation * fix lint
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
.form-container {
|
||||
padding: 10px;
|
||||
}
|
@@ -1,6 +1,19 @@
|
||||
<div class="form-container">
|
||||
<adf-form
|
||||
[showRefreshButton]="false"
|
||||
[form]="form">
|
||||
</adf-form>
|
||||
<div class="main-content">
|
||||
<h1>Form Component</h1>
|
||||
|
||||
<div class="form-container">
|
||||
<adf-form
|
||||
[showRefreshButton]="false"
|
||||
[form]="form"
|
||||
(formError)="logErrors($event)">
|
||||
</adf-form>
|
||||
</div>
|
||||
|
||||
<div class="console" #console>
|
||||
<h3>Error log:</h3>
|
||||
<p *ngFor="let error of errorFields">Error {{ error.name }} {{error.validationSummary.message | translate}}</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
32
demo-shell/src/app/components/form/form.component.scss
Normal file
32
demo-shell/src/app/components/form/form.component.scss
Normal file
@@ -0,0 +1,32 @@
|
||||
.form-container {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
padding: 0 15px;
|
||||
}
|
||||
|
||||
.card-view {
|
||||
width: 30%;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.console {
|
||||
width: 60%;
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
margin-left: 10px;
|
||||
height: 500px;
|
||||
overflow: scroll;
|
||||
padding-bottom: 30px;
|
||||
|
||||
h3 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
p {
|
||||
display: block;
|
||||
font-family: monospace, monospace;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
@@ -15,45 +15,38 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, Inject, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { FormModel, FormService, FormOutcomeEvent } from '@alfresco/adf-core';
|
||||
import { Component, Inject, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { FormModel, FormFieldModel, FormService, FormOutcomeEvent } from '@alfresco/adf-core';
|
||||
import { InMemoryFormService } from '../../services/in-memory-form.service';
|
||||
import { DemoForm } from './demo-form';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-form',
|
||||
templateUrl: 'form.component.html',
|
||||
styleUrls: ['form.component.css'],
|
||||
styleUrls: ['form.component.scss'],
|
||||
providers: [
|
||||
{ provide: FormService, useClass: InMemoryFormService }
|
||||
],
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class FormComponent implements OnInit {
|
||||
export class FormComponent implements OnInit, OnDestroy {
|
||||
|
||||
form: FormModel;
|
||||
errorFields: FormFieldModel[] = [];
|
||||
private subscriptions: Subscription[] = [];
|
||||
|
||||
constructor(@Inject(FormService) private formService: InMemoryFormService) {
|
||||
formService.executeOutcome.subscribe((formOutcomeEvent: FormOutcomeEvent) => {
|
||||
formOutcomeEvent.preventDefault();
|
||||
});
|
||||
|
||||
this.subscriptions.push(
|
||||
formService.executeOutcome.subscribe((formOutcomeEvent: FormOutcomeEvent) => {
|
||||
formOutcomeEvent.preventDefault();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
logErrors(errorFields: FormFieldModel[]) {
|
||||
this.errorFields = errorFields;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -61,4 +54,9 @@ export class FormComponent implements OnInit {
|
||||
this.form = this.formService.parseForm(formDefinitionJSON);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subscriptions.forEach(subscription => subscription.unsubscribe());
|
||||
this.subscriptions = [];
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user