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