| 1349 | // --- 1. Component Setup --- |
| 1350 | // An FVC custom control designed for Signal Forms, used inside a legacy template-driven `ngModel`. |
| 1351 | @Component({ |
| 1352 | selector: 'legacy-parsing-input', |
| 1353 | template: `<input #i [value]="rawValue()" (input)="rawValue.set(i.value)" />`, |
| 1354 | }) |
| 1355 | class LegacyParsingInput { |
| 1356 | readonly value = model<number | null>(null); |
| 1357 | protected readonly rawValue = transformedValue(this.value, { |
| 1358 | parse: (val) => { |
| 1359 | if (val === '') return {value: null}; |
| 1360 | const num = Number(val); |
| 1361 | if (Number.isNaN(num)) { |
| 1362 | return {error: {kind: 'parse', message: `${val} is not numeric`}}; |
| 1363 | } |
| 1364 | return {value: num}; |
| 1365 | }, |
| 1366 | format: (val) => val?.toString() ?? '', |
| 1367 | }); |
| 1368 | getRawValueSignal() { |
| 1369 | return this.rawValue; |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | @Component({ |
| 1374 | template: `<legacy-parsing-input [(ngModel)]="val" #model="ngModel" />`, |
nothing calls this directly
no test coverage detected