Skip to content

Commit

Permalink
fix(forms): formula fields must be readonly inputs
Browse files Browse the repository at this point in the history
Formula fields are intended to be readonly, their value should be not editable. When a user needs to have a calculated default value for an editable field, standard text/number fields can used
  • Loading branch information
peppedeka authored and trik committed Nov 30, 2020
1 parent a957bfb commit 93c2819
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/core/forms/forms-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {AjfGetTableCellControlPipe} from './get-table-cell-control';
import {AjfImageFieldComponent} from './image-field';
import {AjfIncrementPipe} from './increment';
import {AjfIsCellEditablePipe} from './is-cell-editable';
import {AjfIsReadonlyInputFieldPipe} from './is-readonly-input-field';
import {AjfIsRepeatingSlideInstancePipe} from './is-repeating-slide';
import {AjfNodeCompleteNamePipe} from './node-complete-name';
import {AjfRangePipe} from './range';
Expand Down Expand Up @@ -73,6 +74,7 @@ import {AjfValidationService} from './validation-service';
AjfImageFieldComponent,
AjfIncrementPipe,
AjfIsCellEditablePipe,
AjfIsReadonlyInputFieldPipe,
AjfIsRepeatingSlideInstancePipe,
AjfNodeCompleteNamePipe,
AjfRangePipe,
Expand Down Expand Up @@ -105,6 +107,7 @@ import {AjfValidationService} from './validation-service';
AjfImageFieldComponent,
AjfIncrementPipe,
AjfIsCellEditablePipe,
AjfIsReadonlyInputFieldPipe,
AjfIsRepeatingSlideInstancePipe,
AjfNodeCompleteNamePipe,
AjfRangePipe,
Expand Down
36 changes: 36 additions & 0 deletions src/core/forms/is-readonly-input-field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @license
* Copyright (C) Gnucoop soc. coop.
*
* This file is part of the Advanced JSON forms (ajf).
*
* Advanced JSON forms (ajf) is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Advanced JSON forms (ajf) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Advanced JSON forms (ajf).
* If not, see http://www.gnu.org/licenses/.
*
*/

import {Pipe, PipeTransform} from '@angular/core';

import {AjfFieldInstance} from './interface/fields-instances/field-instance';
import {AjfFieldType} from './interface/fields/field-type';
import {AjfNodeInstance} from './interface/nodes-instances/node-instance';
import {isFieldInstance} from './utils/nodes-instances/is-field-instance';

@Pipe({name: 'ajfIsReadonlyInputField'})
export class AjfIsReadonlyInputFieldPipe implements PipeTransform {
transform(instance: AjfNodeInstance): boolean {
return isFieldInstance(instance) &&
(instance as AjfFieldInstance).node.fieldType === AjfFieldType.Formula;
}
}
1 change: 1 addition & 0 deletions src/core/forms/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export * from './increment';
export * from './input-field';
export * from './image-field';
export * from './is-cell-editable';
export * from './is-readonly-input-field';
export * from './is-repeating-slide';
export * from './node-complete-name';
export * from './range';
Expand Down
3 changes: 2 additions & 1 deletion src/ionic/forms/input-field.html
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<ion-input *ngIf="control|async as ctrl" [type]="type" [formControl]="ctrl!"></ion-input>
<ion-input *ngIf="control|async as ctrl" [type]="type" [formControl]="ctrl!" [readonly]="instance|ajfIsReadonlyInputField">
</ion-input>
3 changes: 1 addition & 2 deletions src/material/forms/input-field.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<mat-form-field *ngIf="control|async as ctrl">
<input matInput *ngIf="type === 'text'" type="text" [formControl]="ctrl!">
<input matInput *ngIf="type === 'number'" type="number" [formControl]="ctrl!">
<input matInput [type]="type" [formControl]="ctrl!" [readonly]="instance|ajfIsReadonlyInputField">
</mat-form-field>
8 changes: 7 additions & 1 deletion tools/public_api_guard/core/forms.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ export declare class AjfFormSerializer {

export declare class AjfFormsModule {
static ɵinj: i0.ɵɵInjectorDef<AjfFormsModule>;
static ɵmod: i0.ɵɵNgModuleDefWithMeta<AjfFormsModule, [typeof i1.AjfAsFieldInstancePipe, typeof i2.AjfAsRepeatingSlideInstancePipe, typeof i3.AjfBoolToIntPipe, typeof i4.AjfDateValuePipe, typeof i5.AjfDateValueStringPipe, typeof i6.AjfExpandFieldWithChoicesPipe, typeof i7.AjfFieldHost, typeof i8.AjfFieldIconPipe, typeof i9.AjfFieldIsValidPipe, typeof i10.AjfFileFieldComponent, typeof i11.AjfGetTableCellControlPipe, typeof i12.AjfImageFieldComponent, typeof i13.AjfIncrementPipe, typeof i14.AjfIsCellEditablePipe, typeof i15.AjfIsRepeatingSlideInstancePipe, typeof i16.AjfNodeCompleteNamePipe, typeof i17.AjfRangePipe, typeof i18.AjfReadOnlyFieldComponent, typeof i19.AjfReadOnlyFileFieldComponent, typeof i20.AjfReadOnlyImageFieldComponent, typeof i21.AjfReadOnlySelectFieldComponent, typeof i22.AjfReadOnlyTableFieldComponent, typeof i23.AjfReadOnlyVideoUrlFieldComponent, typeof i24.AjfTableRowClass, typeof i25.AjfTableVisibleColumnsPipe, typeof i26.AjfValidSlidePipe], [typeof i27.AjfCommonModule, typeof i28.AjfFileInputModule, typeof i29.CommonModule, typeof i30.HttpClientModule, typeof i31.ReactiveFormsModule, typeof i32.TranslateModule], [typeof i1.AjfAsFieldInstancePipe, typeof i2.AjfAsRepeatingSlideInstancePipe, typeof i3.AjfBoolToIntPipe, typeof i4.AjfDateValuePipe, typeof i5.AjfDateValueStringPipe, typeof i6.AjfExpandFieldWithChoicesPipe, typeof i7.AjfFieldHost, typeof i8.AjfFieldIconPipe, typeof i9.AjfFieldIsValidPipe, typeof i10.AjfFileFieldComponent, typeof i11.AjfGetTableCellControlPipe, typeof i12.AjfImageFieldComponent, typeof i13.AjfIncrementPipe, typeof i14.AjfIsCellEditablePipe, typeof i15.AjfIsRepeatingSlideInstancePipe, typeof i16.AjfNodeCompleteNamePipe, typeof i17.AjfRangePipe, typeof i18.AjfReadOnlyFieldComponent, typeof i19.AjfReadOnlyFileFieldComponent, typeof i20.AjfReadOnlyImageFieldComponent, typeof i21.AjfReadOnlySelectFieldComponent, typeof i22.AjfReadOnlyTableFieldComponent, typeof i23.AjfReadOnlyVideoUrlFieldComponent, typeof i24.AjfTableRowClass, typeof i25.AjfTableVisibleColumnsPipe, typeof i26.AjfValidSlidePipe]>;
static ɵmod: i0.ɵɵNgModuleDefWithMeta<AjfFormsModule, [typeof i1.AjfAsFieldInstancePipe, typeof i2.AjfAsRepeatingSlideInstancePipe, typeof i3.AjfBoolToIntPipe, typeof i4.AjfDateValuePipe, typeof i5.AjfDateValueStringPipe, typeof i6.AjfExpandFieldWithChoicesPipe, typeof i7.AjfFieldHost, typeof i8.AjfFieldIconPipe, typeof i9.AjfFieldIsValidPipe, typeof i10.AjfFileFieldComponent, typeof i11.AjfGetTableCellControlPipe, typeof i12.AjfImageFieldComponent, typeof i13.AjfIncrementPipe, typeof i14.AjfIsCellEditablePipe, typeof i15.AjfIsReadonlyInputFieldPipe, typeof i16.AjfIsRepeatingSlideInstancePipe, typeof i17.AjfNodeCompleteNamePipe, typeof i18.AjfRangePipe, typeof i19.AjfReadOnlyFieldComponent, typeof i20.AjfReadOnlyFileFieldComponent, typeof i21.AjfReadOnlyImageFieldComponent, typeof i22.AjfReadOnlySelectFieldComponent, typeof i23.AjfReadOnlyTableFieldComponent, typeof i24.AjfReadOnlyVideoUrlFieldComponent, typeof i25.AjfTableRowClass, typeof i26.AjfTableVisibleColumnsPipe, typeof i27.AjfValidSlidePipe], [typeof i28.AjfCommonModule, typeof i29.AjfFileInputModule, typeof i30.CommonModule, typeof i31.HttpClientModule, typeof i32.ReactiveFormsModule, typeof i33.TranslateModule], [typeof i1.AjfAsFieldInstancePipe, typeof i2.AjfAsRepeatingSlideInstancePipe, typeof i3.AjfBoolToIntPipe, typeof i4.AjfDateValuePipe, typeof i5.AjfDateValueStringPipe, typeof i6.AjfExpandFieldWithChoicesPipe, typeof i7.AjfFieldHost, typeof i8.AjfFieldIconPipe, typeof i9.AjfFieldIsValidPipe, typeof i10.AjfFileFieldComponent, typeof i11.AjfGetTableCellControlPipe, typeof i12.AjfImageFieldComponent, typeof i13.AjfIncrementPipe, typeof i14.AjfIsCellEditablePipe, typeof i15.AjfIsReadonlyInputFieldPipe, typeof i16.AjfIsRepeatingSlideInstancePipe, typeof i17.AjfNodeCompleteNamePipe, typeof i18.AjfRangePipe, typeof i19.AjfReadOnlyFieldComponent, typeof i20.AjfReadOnlyFileFieldComponent, typeof i21.AjfReadOnlyImageFieldComponent, typeof i22.AjfReadOnlySelectFieldComponent, typeof i23.AjfReadOnlyTableFieldComponent, typeof i24.AjfReadOnlyVideoUrlFieldComponent, typeof i25.AjfTableRowClass, typeof i26.AjfTableVisibleColumnsPipe, typeof i27.AjfValidSlidePipe]>;
}

export interface AjfFormStringIdentifier {
Expand Down Expand Up @@ -492,6 +492,12 @@ export declare class AjfIsCellEditablePipe implements PipeTransform {
static ɵpipe: i0.ɵɵPipeDefWithMeta<AjfIsCellEditablePipe, "ajfIsCellEditable">;
}

export declare class AjfIsReadonlyInputFieldPipe implements PipeTransform {
transform(instance: AjfNodeInstance): boolean;
static ɵfac: i0.ɵɵFactoryDef<AjfIsReadonlyInputFieldPipe, never>;
static ɵpipe: i0.ɵɵPipeDefWithMeta<AjfIsReadonlyInputFieldPipe, "ajfIsReadonlyInputField">;
}

export declare class AjfIsRepeatingSlideInstancePipe implements PipeTransform {
transform(instance: AjfNodeInstance): boolean;
static ɵfac: i0.ɵɵFactoryDef<AjfIsRepeatingSlideInstancePipe, never>;
Expand Down

0 comments on commit 93c2819

Please sign in to comment.