| 1436 | // --- 1. Component Setup --- |
| 1437 | // An FVC custom control designed for Signal Forms, used inside a legacy template-driven `ngModel`. |
| 1438 | @Component({ |
| 1439 | selector: 'legacy-parsing-input', |
| 1440 | template: `<input #i [value]="rawValue()" (input)="rawValue.set(i.value)" />`, |
| 1441 | }) |
| 1442 | class LegacyParsingInput { |
| 1443 | readonly value = model<number | null>(null); |
| 1444 | protected readonly rawValue = transformedValue(this.value, { |
| 1445 | parse: (val) => { |
| 1446 | if (val === '') return {value: null}; |
| 1447 | const num = Number(val); |
| 1448 | if (Number.isNaN(num)) { |
| 1449 | return {error: {kind: 'parse', message: `${val} is not numeric`}}; |
| 1450 | } |
| 1451 | return {value: num}; |
| 1452 | }, |
| 1453 | format: (val) => val?.toString() ?? '', |
| 1454 | }); |
| 1455 | getRawValueSignal() { |
| 1456 | return this.rawValue; |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | @Component({ |
| 1461 | template: `<legacy-parsing-input [(ngModel)]="val" #model="ngModel" />`, |
nothing calls this directly
no test coverage detected