dynaform.component.html 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <ng-container *ngFor="let rowName of dynaFormRows">
  2. <ng-container *ngTemplateOutlet="template ? template : default; context: getTemplateContext(rowName)"></ng-container>
  3. </ng-container>
  4. <!-- Default template for form field
  5. used when a TemplateRef is NOT supplied to component -->
  6. <ng-template let-control="control" let-meta="meta" #default>
  7. <ng-container *ngIf="meta.type !== 'Hidden'">
  8. <ng-container *ngIf="!meta.noLabel; else fullWidth">
  9. <div class="form-group row" *ngIf="isField(meta); else recursiveDynaform" [ngClass]="getRowClass(control, meta)">
  10. <label class="col-sm-4" [ngClass]="meta.class" [for]="meta.name" title="">
  11. {{ meta.rowLabel ? meta.rowLabel : meta.label }}
  12. <span *ngIf="control && control.touched && control.invalid" class="fas fa-exclamation-triangle"
  13. [ngbTooltip]="getValidationFailureMessage(control, meta)"
  14. ></span>
  15. </label>
  16. <div class="col-sm-8">
  17. <ng-container dynafield
  18. [control]="control"
  19. [meta]="meta"
  20. (call)="handleCallback($event)"
  21. ></ng-container>
  22. </div>
  23. </div>
  24. </ng-container>
  25. <ng-template #recursiveDynaform>
  26. <ng-container *ngIf="isRepeatingContainer(meta); else container">
  27. <div *ngIf="meta.display === 'SINGLE'" class="row dyna-repeating-container-selector">
  28. <div class="col-sm-4 text-right">
  29. <b>FOCUS &gt;</b>
  30. </div>
  31. <div class="col-sm-8">
  32. <a *ngFor="let container of meta.meta; let i = index"
  33. class="btn btn-sm"
  34. [ngClass]="container.focussed ? 'btn-primary' : 'btn-outline-primary'"
  35. (click)="focusContainer(meta.name, i)">
  36. {{ getRCLabel(meta.name, i) }}
  37. </a>
  38. <a *ngIf="meta.showAddControl"
  39. class="btn btn-sm btn-outline-success"
  40. (click)="addRCMember(meta.name)">
  41. + Add New
  42. </a>
  43. </div>
  44. </div>
  45. <div *ngFor="let container of meta.meta; let i = index" class="dyna-rc-container" [ngClass]="{ 'dyna-rc-display-all': meta.display === 'ALL' }">
  46. <ng-container *ngTemplateOutlet="dynaform; context: getRCTemplateContext(meta.name, i)"></ng-container>
  47. </div>
  48. <div *ngIf="meta.showAddControl && meta.display === 'ALL'" class="row">
  49. <div class="col-sm-12">
  50. <a class="btn btn-sm btn-outline-success" (click)="addRCMember(meta.name)">
  51. + Add New
  52. </a>
  53. </div>
  54. </div>
  55. </ng-container>
  56. </ng-template>
  57. <ng-template #container>
  58. <ng-container *ngTemplateOutlet="dynaform; context: { control: control, meta: meta }"></ng-container>
  59. </ng-template>
  60. <ng-template #fullWidth>
  61. <div class="row" [ngClass]="getRowClass(control, meta.type)">
  62. <ng-container dynafield [control]="control" [meta]="meta" (call)="handleCallback($event)"></ng-container>
  63. </div>
  64. </ng-template>
  65. </ng-container>
  66. </ng-template>
  67. <ng-template let-control="control" let-meta="meta" #dynaform>
  68. <div *ngIf="meta.label" class="row">
  69. <h3 class="col-sm-12 h-dyna" [ngClass]="'h-dyna-' + (path.length + 2)">{{ meta.label }}</h3>
  70. </div>
  71. <app-dynaform [formGroup]="control" [meta]="meta.meta" [template]="template" [ngClass]="{ 'dyna-hidden': !meta.focussed }" (call)="handleCallback($event)"></app-dynaform>
  72. </ng-template>
  73. <!-- Display validation status if debugging and not nested -->
  74. <div *ngIf="debug && path.length === 0">
  75. <pre [ngClass]="{
  76. 'alert-success' : formGroup.valid && formGroup.dirty,
  77. 'alert-danger' : !formGroup.valid && formGroup.dirty,
  78. 'alert-secondary' : !formGroup.dirty
  79. }"
  80. class="alert __debug mt-4"
  81. role="alert">{{ formGroup.pristine ? 'Untouched' : getValidationErrors() | json }}</pre>
  82. </div>