argos/dmp-frontend/src/app/form/fields/dynamic-form-field.componen...

144 lines
5.9 KiB
HTML

<!-- <div [formGroup]="form" class="form-group">
<label [attr.for]="field.key">{{field.label}}</label>
<div [ngSwitch]="field.controlType">
<input *ngSwitchCase="'textbox'" class ="form-control" [formControlName]="field.key"
[id]="field.key" [type]="field.type" required ="field.required">
<select [id]="field.key" *ngSwitchCase="'dropdown'" class ="form-control" [formControlName]="field.key">
<option *ngFor="let opt of field.options" [value]="opt.key">{{opt.value}}</option>
</select>
<input *ngSwitchCase="'checkbox'" [formControlName]="field.key" [(ngModel)]="field.value"
[id]="field.key" [type]="field.type" (change)="field.value = ckb.checked" #ckb>
</div>
<div class="alert alert-danger" *ngIf="!isValid">{{field.label}} is required</div>
</div> -->
<div *ngIf="this.visibilityRulesService.isElementVisible(pathName,field.id)" [formGroup]="form" class="form-group" [ngSwitch]="field.viewStyle">
<div [ngClass]="{true:'show', false:'hide'}[field.visible]">
<label>{{field.description}}</label>
<div>{{field.extendedDescription}}</div>
<div *ngSwitchCase="'freetext'">
<input class="form-control" formControlName="value">
</div>
<!--input or change event
on change event the listener is triggered on blur -->
<!-- <div *ngSwitchCase="'dropdown'">
<autocomplete-remote *ngIf="field.url" formControlName="value" [url]="field.url" ></autocomplete-remote>
<select *ngIf="!field.url" class="form-control" [id]="field.key" formControlName="field.key" [required]="field.required" (change)="toggleVisibility($event, field, false)">
<option *ngFor="let opt of field.options" [value]="opt._value" >{{opt._label}}</option>
</select>
</div> -->
<div *ngSwitchCase="'comboBox'">
<!--TODO-->
<autocomplete-remote *ngIf="field.url" formControlName="value" [url]="field.url"></autocomplete-remote>
<select *ngIf="!field.url" class="form-control" [id]="field.key" formControlName="value">
<option *ngFor="let opt of field.options" >{{opt._label}}</option>
</select>
</div>
<!-- <div *ngSwitchCase="'checkbox'" class="checkbox">
<label class="checkBoxLabelCustom">
<input *ngSwitchCase="'checkbox'" class="form-check" formControlName="value" [type]="field.type"
(change)="toggleVisibility($event, field, true)" [required]="field.required" [checked]="form.get(field.key).value">{{field.label}}
</label>
</div> -->
<div *ngSwitchCase="'checkBox'" class="checkbox">
<label class="checkBoxLabelCustom">
<input class="form-check" formControlName="value" type="checkbox">{{field.title}}
</label>
</div>
<div *ngSwitchCase="'textarea'">
<textarea class="form-control" formControlName="value"> </textarea>
</div>
<div *ngSwitchCase="'radiobox'">
<ng-container *ngFor="let answrBase of field.answers">
<div style="display: inline-block;margin-right:10px;" [id]="field.key">
<label for="{{answrBase.id}}" style="padding: 8px 10px; padding-right:5px;">{{answrBase.answer}}</label>
<input type="radio" [formControlName]="value" [id]="answrBase.id" [value]="answrBase.value" [(ngModel)]="field.value" (change)="toggleVisibility($event, field,false)"
[required]="field.required" />
</div>
</ng-container>
</div>
</div>
<div *ngSwitchCase="'label'"> </div>
<div [hidden]="isValid">
<div class="invalid-feedbackCustom" *ngIf="isValidRequired">The field "{{field.label}}" is required</div>
<div class="invalid-feedbackCustom" *ngIf="isValidPattern">The field {{field.label}} must match a regular expression {{field.regex}}</div>
<div class="invalid-feedbackCustom" *ngIf="isValidCustom">The field {{field.label}} custom Validation</div>
</div>
</div>
<!-- <div [formGroup]="form" class="form-group" [ngSwitch]="field.controlType">
<div *ngIf= "field.rules; else elseBlock ">
<div *ngIf="field.rules.length > 0; else elseBlock">
<div *ngFor="let rule of field.rules">
<div *ngIf="rule._type == 'fieldVisible'; else otherRuleBlock">
<div hidden="{{ruleVisibleMethod(field, rule, dataModel)}}">
<label [attr.for]="field.key">{{field.label}}</label>
<input *ngSwitchCase="'textbox'" class="form-control" [formControlName]="field.key" [id]="field.key" [type]="field.type"
required="field.required">
<select [id]="field.key" *ngSwitchCase="'dropdown'" class="form-control" [formControlName]="field.key">
<option *ngFor="let opt of field.options" [value]="opt.key">{{opt.value}}</option>
</select>
<input *ngSwitchCase="'checkbox'" [formControlName]="field.key" [(ngModel)]="field.value" [id]="field.key" [type]="field.type"
(change)="field.value = ckb.checked" #ckb>
</div>
</div>
</div>
</div>
</div>
<ng-template #elseBlock>
<label [attr.for]="field.key">{{field.label}}</label>
<input *ngSwitchCase="'textbox'" class="form-control" [formControlName]="field.key" [id]="field.key" [type]="field.type"
required="field.required">
<select [id]="field.key" *ngSwitchCase="'dropdown'" class="form-control" [formControlName]="field.key">
<option *ngFor="let opt of field.options" [value]="opt.key">{{opt.value}}</option>
</select>
<input *ngSwitchCase="'checkbox'" [formControlName]="field.key" [(ngModel)]="field.value" [id]="field.key" [type]="field.type"
(change)="field.value = ckb.checked" #ckb>
</ng-template>
<ng-template #otherRuleBlock>
</ng-template>
</div> -->