fix: mark input as dirty after patching value

This commit is contained in:
2026-02-22 15:52:23 -03:00
parent 9b3e42a161
commit d25b7cb49c
2 changed files with 15 additions and 1 deletions

View File

@@ -12,4 +12,4 @@
</button> </button>
</div> </div>
</div> </div>
<app-bar-code-reader [scan]="scan()" (result)="control.patchValue($event.detail?.code?.rawValue ?? '')"></app-bar-code-reader> <app-bar-code-reader [scan]="scan()" (result)="updateBarcode($event)"></app-bar-code-reader>

View File

@@ -7,6 +7,7 @@ import { BarCodeReaderWrapper } from '../bar-code-reader/bar-code-reader';
import { ControlValueAccessor, FormControl, NgControl, ReactiveFormsModule } from '@angular/forms'; import { ControlValueAccessor, FormControl, NgControl, ReactiveFormsModule } from '@angular/forms';
import { UpperfirstPipe } from '../../pipes/upperfirst-pipe'; import { UpperfirstPipe } from '../../pipes/upperfirst-pipe';
import { TranslatePipe } from '@ngx-translate/core'; import { TranslatePipe } from '@ngx-translate/core';
import { DetectedBarcode } from '../../types/globalThis';
@Component({ @Component({
selector: 'app-bar-code-input', selector: 'app-bar-code-input',
@@ -38,6 +39,19 @@ export class BarCodeInput implements ControlValueAccessor, OnInit {
this.control = <FormControl>this.controlDir?.control; this.control = <FormControl>this.controlDir?.control;
} }
updateBarcode(
barcodeEvent: Event & {
detail?: {
code: DetectedBarcode | null;
};
},
) {
let code = barcodeEvent.detail?.code?.rawValue
if(code) {
this.control.patchValue(code);
this.control.markAsDirty();
}
}
writeValue(obj: any): void {} writeValue(obj: any): void {}
registerOnChange(fn: any): void {} registerOnChange(fn: any): void {}
registerOnTouched(fn: any): void {} registerOnTouched(fn: any): void {}