Skip to content

Commit 5f86931

Browse files
authored
Merge pull request #168 from CloudInn/listing-enhancements
Add option to hide form fields from listing, remove validations from …
2 parents 01f5602 + 560d194 commit 5f86931

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

projects/crud/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng-crud-ui",
3-
"version": "5.10.19",
3+
"version": "5.10.20",
44
"dependencies": {
55
"tslib": "^2.0.0"
66
},

projects/crud/src/lib/components/form-field/form-field.component.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ng-container [ngSwitch]="config?.type" [formGroup]="formGroup">
1+
<ng-container [ngSwitch]="config?.type" [formGroup]="formGroup" *ngIf="config?.showInListing !== false || mode !== 'search'">
22

33
<ng-container *ngSwitchCase="'boolean'">
44
<div class="checkbox-container">
@@ -51,12 +51,14 @@
5151
<mat-form-field *ngSwitchDefault>
5252
<mat-label>{{ config?.label }}</mat-label>
5353
<input matInput [formControlName]="config?.name" attr.data-cy="{{config.label | getSelector}}-input" id="{{config?.name}}-field" [maxlength]="config?.maxlength" [required]="f[config?.name].hasError('required') && mode !== 'search'" [type]="config?.control ? config?.control.type : 'text'" [readonly]="config.disabled !== undefined ? config.disabled : false"/>
54-
<mat-error *ngIf="mode !== 'search' && f[config.name].hasError('required') && (f[config.name].dirty || f[config.name].touched)" id="{{config.name}}-required-error">
55-
this field is required</mat-error>
56-
<mat-error *ngIf="f[config.name].hasError('maxlength') && (f[config.name].dirty || f[config.name].touched)" id="{{config.name}}-maxLength-error">
57-
max length is {{config?.maxlength}} characters</mat-error>
58-
<mat-error *ngIf="f[config.name].hasError('pattern') && (f[config.name].dirty || f[config.name].touched)" id="{{config.name}}-pattern-error">
59-
{{getFieldErrorMessage("pattern")? getFieldErrorMessage("pattern"): "pattern for this field is invalid"}}
60-
</mat-error>
54+
<ng-container *ngIf="mode !== 'search'">
55+
<mat-error *ngIf="f[config.name].hasError('required') && (f[config.name].dirty || f[config.name].touched)" id="{{config.name}}-required-error">
56+
this field is required</mat-error>
57+
<mat-error *ngIf="f[config.name].hasError('maxlength') && (f[config.name].dirty || f[config.name].touched)" id="{{config.name}}-maxLength-error">
58+
max length is {{config?.maxlength}} characters</mat-error>
59+
<mat-error *ngIf="f[config.name].hasError('pattern') && (f[config.name].dirty || f[config.name].touched)" id="{{config.name}}-pattern-error">
60+
{{getFieldErrorMessage("pattern")? getFieldErrorMessage("pattern"): "pattern for this field is invalid"}}
61+
</mat-error>
62+
</ng-container>
6163
</mat-form-field>
6264
</ng-container>

projects/crud/src/lib/components/form-field/form-field.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class FormFieldComponent implements OnChanges, OnInit {
3737
}
3838
});
3939
}
40+
this.checkValidity();
4041
}
4142

4243
deleteAttachment(event) {

projects/crud/src/lib/components/model-form/model-form.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ export class ModelFormComponent implements OnInit, OnDestroy {
342342
} else {
343343
this.initialLoading = false;
344344
const contains_ctrl = this.viewConfig.controls.filter(ctrl => ctrl.iContains);
345+
this.viewConfig.controls.forEach(ctrl => {
346+
if (ctrl.showInListing === false && this.formGroup.value.hasOwnProperty(ctrl.name)) {
347+
delete this.formGroup.value[ctrl.name];
348+
}
349+
});
345350
this.submit.emit({ ...this.formGroup.value, iContains: contains_ctrl });
346351
}
347352
} else {

projects/crud/src/lib/models/metadata.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export class FieldConfig {
8282
cellStyle?: {};
8383
dropDownDisplay?: string;
8484
DatePickerStartAt?: any;
85+
showInListing?: boolean;
8586
}
8687

8788
export interface CustomElementConfig {

0 commit comments

Comments
 (0)