-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(forms): formula fields must be readonly inputs
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
Showing
6 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters