@ng2-dynamic-forms/ui-foundation
Version:
Foundation UI package for ng2 Dynamic Forms
235 lines (177 loc) • 10.5 kB
HTML
<div [formGroup]="group" [ngClass]="[model.cls.element.container, model.cls.grid.container]">
<div *ngIf="type !== 2 && model.label !== null"
[]="model.cls.grid.label">
<label [attr.for]="model.id"
[]="hasErrorMessaging && !hasFocus && isInvalid"
[]="model.label"
[]="model.cls.element.label"></label>
</div>
<ng-template *ngIf="type !== 1 && template?.align === 'START'"
[]="template.templateRef"
[]="model"></ng-template>
<div [ngClass]="model.cls.grid.control">
<ng-container [ngSwitch]="type">
<div *ngSwitchCase="1"
[]="bindId && model.id"
[]="model.id"
[]="model.cls.element.control">
<div *ngFor="let groupModel of model.groups; let idx = index" role="group"
[]="idx" [ngClass]="[model.cls.element.group, model.cls.grid.group]">
<dynamic-form-foundation-sites-control *ngFor="let item of groupModel.group"
[]="false"
[]="groupModel"
[]="control.at(idx)"
[]="item.hasErrorMessages"
[]="item"
[]="templates"
[]="[item.cls.element.host, item.cls.grid.host]"
(blur)="onFocusChange($event)"
(change)="onValueChange($event)"
(focus)="onFocusChange($event)"></dynamic-form-foundation-sites-control>
<ng-container *ngTemplateOutlet="template?.templateRef; context: groupModel"></ng-container>
</div>
</div>
<label *ngSwitchCase="2">
<input type="checkbox"
[]="model.tabIndex"
[]="model.checked"
[]="bindId && model.id"
[]="model.id"
[]="model.name"
[]="model.cls.element.control"
[]="model.required"
[]="model.value"
(blur)="onFocusChange($event)"
(change)="onValueChange($event)"
(focus)="onFocusChange($event)"/><span
[]="[model.cls.element.label, model.cls.grid.label]"
[]="model.label"></span></label>
<fieldset *ngSwitchCase="3"
[]="bindId && model.id"
[]="model.id"
[]="model.name"
[]="model.cls.element.control">
<legend *ngIf="model.legend">{{model.legend}}</legend>
<dynamic-form-foundation-sites-control *ngFor="let itemModel of model.group"
[]="control"
[]="itemModel.hasErrorMessages"
[]="itemModel"
[]="templates"
[]="[itemModel.cls.element.host, itemModel.cls.grid.host]"
(blur)="onFocusChange($event)"
(change)="onValueChange($event)"
(focus)="onFocusChange($event)"></dynamic-form-foundation-sites-control>
</fieldset>
<div *ngSwitchCase="4" class="input-group">
<span *ngIf="model.prefix" class="input-group-label" [innerHTML]="model.prefix"></span>
<input class="input-group-field"
[]="model.accept"
[]="model.autoComplete"
[]="model.listId"
[]="model.max"
[]="model.min"
[]="model.multiple"
[]="model.step"
[]="model.tabIndex"
[]="model.autoFocus"
[]="hasErrorMessaging && !hasFocus && isInvalid"
[]="bindId && model.id"
[]="model.id"
[]="model.maxLength"
[]="model.minLength"
[]="model.name"
[]="model.cls.element.control"
[]="model.pattern"
[]="model.placeholder"
[]="model.readOnly"
[]="model.required"
[]="model.spellCheck"
[]="{mask: (model.mask || false), showMask: model.mask && !(model.placeholder)}"
[]="model.inputType"
(blur)="onFocusChange($event)"
(change)="onValueChange($event)"
(focus)="onFocusChange($event)"/>
<span *ngIf="model.suffix" class="input-group-label" [innerHTML]="model.suffix"></span>
<datalist *ngIf="model.list" [id]="model.listId">
<option *ngFor="let option of model.list" [value]="option">
</datalist>
</div>
<fieldset *ngSwitchCase="5" role="radiogroup"
[]="model.tabIndex"
[]="bindId && model.id"
[]="model.name"
(change)="onValueChange($event)">
<legend *ngIf="model.legend" [innerHTML]="model.legend"></legend>
<label *ngFor="let option of model.options$ | async">
<input type="radio"
[]="model.id"
[]="model.name"
[]="model.cls.element.control"
[]="option.value"
(blur)="onFocusChange($event)"
(focus)="onFocusChange($event)"/><span [innerHTML]="option.label"></span></label>
</fieldset>
<select *ngSwitchCase="6"
[]="model.tabIndex"
[]="bindId && model.id"
[]="model.id"
[]="model.name"
[]="model.cls.element.control"
[]="model.required"
(blur)="onFocusChange($event)"
(change)="onValueChange($event)"
(focus)="onFocusChange($event)">
<option *ngFor="let option of model.options$ | async"
[]="model.name"
[]="option.value">{{option.label}}
</option>
</select>
<div *ngSwitchCase="7" class="switch" [ngClass]="model.cls.element.control">
<input type="checkbox" class="switch-input"
[]="model.tabIndex"
[]="model.checked"
[]="bindId && model.id"
[]="model.id"
[]="model.name"
[]="model.required"
[]="model.value"
(blur)="onFocusChange($event)"
(change)="onValueChange($event)"
(focus)="onFocusChange($event)"/>
<label class="switch-paddle" [attr.for]="model.id">
<span class="switch-active" aria-hidden="true">{{model.onLabel}}</span>
<span class="switch-inactive" aria-hidden="true">{{model.offLabel}}</span>
</label>
</div>
<textarea *ngSwitchCase="8"
[]="model.tabIndex"
[]="hasErrorMessaging && !hasFocus && isInvalid"
[]="model.cols"
[]="bindId && model.id"
[]="model.id"
[]="model.maxLength"
[]="model.minLength"
[]="model.name"
[]="model.cls.element.control"
[]="model.placeholder"
[]="model.readOnly"
[]="model.required"
[]="model.rows"
[]="model.spellCheck"
[]="model.wrap"
(blur)="onFocusChange($event)"
(change)="onValueChange($event)"
(focus)="onFocusChange($event)"></textarea>
</ng-container>
<p *ngIf="hasHint" class="help-text" [ngClass]="model.cls.element.hint" [innerHTML]="model.hint"></p>
</div>
<ul *ngIf="hasErrorMessaging" [ngClass]="[model.cls.element.errors, model.cls.grid.errors]">
<li *ngFor="let message of errorMessages" class="form-error"
[]="showErrorMessages">{{message}}
</li>
</ul>
<ng-template *ngIf="type !== 1 && template?.align === 'END'"
[]="template.templateRef"
[]="model"></ng-template>
<ng-content></ng-content>
</div>