diff --git a/frontend/src/app/jira-control/input/input.component.html b/frontend/src/app/jira-control/input/input.component.html index a3731a19..5774610d 100644 --- a/frontend/src/app/jira-control/input/input.component.html +++ b/frontend/src/app/jira-control/input/input.component.html @@ -7,7 +7,8 @@ - - \ No newline at end of file + diff --git a/frontend/src/app/jira-control/input/input.component.spec.ts b/frontend/src/app/jira-control/input/input.component.spec.ts index cb78076c..ddf8a03f 100644 --- a/frontend/src/app/jira-control/input/input.component.spec.ts +++ b/frontend/src/app/jira-control/input/input.component.spec.ts @@ -6,11 +6,6 @@ describe('InputComponent', () => { beforeEach(() => { component = new InputComponent(); }); - - it('should be able to init', () => { - component.ngOnInit(); - expect(component.control).toBeTruthy(); - }); it('should be able to get icon size', () => { expect(component.iconContainerWidth).toEqual(32); }); @@ -18,9 +13,7 @@ describe('InputComponent', () => { expect(typeof component.isShowClearButton).toEqual('undefined'); }); it('should be able to clear control', () => { - component.ngOnInit(); - spyOn(component.control, 'patchValue').and.callThrough(); component.clear(); - expect(component.control.patchValue).toHaveBeenCalled(); + expect(component.value).toHaveBeenCalled(); }); }); diff --git a/frontend/src/app/jira-control/input/input.component.ts b/frontend/src/app/jira-control/input/input.component.ts index 45b3528d..e090080b 100644 --- a/frontend/src/app/jira-control/input/input.component.ts +++ b/frontend/src/app/jira-control/input/input.component.ts @@ -1,34 +1,55 @@ -import { Component, OnInit, Input } from '@angular/core'; -import { FormControl } from '@angular/forms'; +import {ChangeDetectionStrategy, Component, forwardRef, Input} from '@angular/core'; +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms'; @Component({ selector: 'j-input', templateUrl: './input.component.html', - styleUrls: ['./input.component.scss'] + styleUrls: ['./input.component.scss'], + providers: [{ + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => InputComponent), + multi: true, + }], }) -export class InputComponent implements OnInit { - @Input() control: FormControl; +export class InputComponent implements ControlValueAccessor { @Input() containerClassName = ''; @Input() icon: string; @Input() iconSize = 16; @Input() placeholder = ''; @Input() enableClearButton: boolean; + public value; + get iconContainerWidth(): number { return this.iconSize * 2; } get isShowClearButton(): boolean { - return this.enableClearButton && this.control?.value; + return this.enableClearButton && this.value; + } + + registerOnChange(fn: any) { + this.onChange = fn; } - constructor() {} + registerOnTouched(fn: () => {}): void { + this.onTouched = fn; + } - ngOnInit(): void { - this.control = this.control ?? new FormControl(''); + writeValue(outsideValue: string) { + this.value = outsideValue; + } + + updateValue(insideValue: string) { + this.value = insideValue; + this.onChange(insideValue); + this.onTouched(); } clear() { - this.control.patchValue(''); + this.updateValue(''); } + + private onChange = (value: any) => {}; + private onTouched = () => {}; } diff --git a/frontend/src/app/project/components/board/board-filter/board-filter.component.html b/frontend/src/app/project/components/board/board-filter/board-filter.component.html index bc6fae7f..dfc3e62c 100644 --- a/frontend/src/app/project/components/board/board-filter/board-filter.component.html +++ b/frontend/src/app/project/components/board/board-filter/board-filter.component.html @@ -1,8 +1,8 @@