import { Component, Input, OnInit, Optional } from '@angular/core'; import { FormGroupDirective, ValidatorFn, Validators } from '@angular/forms'; import { MaxDesignationLength, ValidatorsService } from '@core/services/validators.service'; import { BaseApplication } from '@core/typings/application.typing'; import { FormBuilderService } from '@features/formio/form-builder/services/form-builder/form-builder.service'; import { GcFormRendererComponent } from '@features/formio/form-renderer/gc-form-renderer/gc-form-renderer.component'; import { ComponentHelperService } from '@features/formio/services/component-helper/component-helper.service'; import { TypeSafeFormBuilder } from '@yourcause/common'; import { BaseFormioComponent } from '../../base/base.component'; @Component({ selector: 'gc-designation', templateUrl: './gc-designation.component.html', styleUrls: ['gc-designation.component.scss'] }) export class GcDesignationComponent extends BaseFormioComponent implements OnInit { @Input() disabled: boolean; constructor ( public formBuilder: TypeSafeFormBuilder, private validatorService: ValidatorsService, public formBuilderService: FormBuilderService, public componentHelper: ComponentHelperService, @Optional() formGroupDir: FormGroupDirective, @Optional() renderer: GcFormRendererComponent ) { super(renderer, formGroupDir, formBuilder, formBuilderService, componentHelper); } ngOnInit () { super.ngOnInit(); if (this.comp) { let validators: ValidatorFn[] = []; if (!this.inFormBuilder) { validators = [ ...this.validatorService.getValidatorsForSimpleComponent( this.comp, false, false, false, this.translations ), Validators.maxLength(MaxDesignationLength) ]; } this.setFormGroup(this.data || '', validators); } } patchValue () { if (this.formGroup && this.formGroup.get(this.compKey)) { this.formGroup.get(this.compKey).setValue(this.data || ''); } } dataChanged (value: string) { this.onValueChange.emit({ value, updateFormGroup: false }); } }