libs/rucken/ionic/src/lib/components/form-group/form-group.component.ts
changeDetection | ChangeDetectionStrategy.OnPush |
selector | form-group |
templateUrl | form-group.component.html |
checkIsDirty
|
Type:
Default value: |
form
|
Type:
Default value: |
name
|
Type:
Default value: |
title
|
Type:
Default value: |
tooltipPlacement
|
Type:
Default value: |
constructor(_renderer: Renderer2, _elementRef: any)
|
getValid |
getValid()
|
Returns:
void
|
errors$ |
errors$: |
input |
input: |
import { AfterViewInit, ChangeDetectionStrategy, Component, ElementRef, Input, OnChanges, Renderer2, SimpleChanges } from '@angular/core';
import { BindIoInner } from 'ngx-bind-io';
import { DynamicFormGroup } from 'ngx-dynamic-form-builder';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
@BindIoInner()
@Component({
selector: 'form-group',
templateUrl: './form-group.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class FormGroupComponent implements AfterViewInit, OnChanges {
@Input()
checkIsDirty?: boolean = undefined;
@Input()
tooltipPlacement?: string = undefined;
@Input()
form: DynamicFormGroup<any> = undefined;
@Input()
name: string = undefined;
@Input()
title: string = undefined;
input: { focus: () => void };
errors$: Observable<any>;
constructor(private _renderer: Renderer2, private _elementRef: ElementRef) { }
ngAfterViewInit() {
this.input = this._elementRef.nativeElement.querySelector('ion-item').querySelector('ion-input');
}
ngOnChanges(changes: SimpleChanges) {
if (changes.form && changes.form.currentValue) {
this.errors$ = changes.form.currentValue.customValidateErrors.pipe(
map(customValidateErrors =>
(
(this.checkIsDirty !== true || changes.form.currentValue.dirty) &&
customValidateErrors[this.name]
) ? (customValidateErrors[this.name] as string[]) : []
)
);
}
}
getValid() {
return !this.form || this.form.get(this.name).valid;
}
}