| 1403 | // --- 1. Component Setup --- |
| 1404 | // An FVC custom control designed for Signal Forms, used inside a legacy template-driven `ngModel`. |
| 1405 | @Component({ |
| 1406 | selector: 'legacy-parsing-input', |
| 1407 | template: `<input #i [value]="rawValue()" (input)="rawValue.set(i.value)" />`, |
| 1408 | }) |
| 1409 | class LegacyParsingInput { |
| 1410 | readonly value = model<number | null>(null); |
| 1411 | protected readonly rawValue = transformedValue(this.value, { |
| 1412 | parse: (val) => { |
| 1413 | if (val === '') return {value: null}; |
| 1414 | const num = Number(val); |
| 1415 | if (Number.isNaN(num)) { |
| 1416 | return {error: {kind: 'parse', message: `${val} is not numeric`}}; |
| 1417 | } |
| 1418 | return {value: num}; |
| 1419 | }, |
| 1420 | format: (val) => val?.toString() ?? '', |
| 1421 | }); |
| 1422 | getRawValueSignal() { |
| 1423 | return this.rawValue; |
| 1424 | } |
| 1425 | } |
| 1426 | |
| 1427 | @Component({ |
| 1428 | template: `<legacy-parsing-input [(ngModel)]="val" #model="ngModel" />`, |
nothing calls this directly
no test coverage detected