fix(frontend): keep integer property fields editable by replacing the crashing Formly number parser#6058
Conversation
… crashing Formly number parser
@ngx-formly/core's json-schema integer/number parser reads
document.querySelector('#'+field.id).validity.badInput, assuming the id is on the
native <input>. ng-zorro's nz-input-number puts the id on its host element, which has
no .validity, so the parser throws 'Cannot read properties of undefined (reading
badInput)' whenever the parsed value is null (an intermediate state while typing).
Typed edits then never commit and the field is stuck (only the +/- steppers work).
Replace the numeric fields' parser in jsonSchemaMapIntercept with a null-safe parser
that does no DOM access.
Automated Reviewer SuggestionsBased on the
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6058 +/- ##
============================================
+ Coverage 56.37% 56.40% +0.02%
Complexity 2992 2992
============================================
Files 1129 1130 +1
Lines 43802 43816 +14
Branches 4743 4749 +6
============================================
+ Hits 24695 24714 +19
+ Misses 17658 17650 -8
- Partials 1449 1452 +3
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
/request-review @mengw15 |
There was a problem hiding this comment.
Pull request overview
Fixes a frontend regression where typing into integer/number operator property fields (e.g., Limit) stops committing changes due to @ngx-formly/core’s json-schema numeric parser doing DOM access (.validity.badInput) that crashes with ng-zorro’s nz-input-number.
Changes:
- Introduce a DOM-free, null-safe numeric parser (
parseNumericInput) and a helper to swap it in for numeric Formly fields (applySafeNumericParser). - Hook the safe parser replacement into the JSONSchema→Formly mapping path for operator properties.
- Add unit tests covering numeric parsing edge cases and ensuring the replacement avoids the prior crash behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| frontend/src/app/workspace/component/property-editor/operator-property-edit-frame/operator-property-edit-frame.component.ts | Applies the safe numeric parser during JSON schema → Formly field mapping for operator property forms. |
| frontend/src/app/workspace/component/property-editor/operator-property-edit-frame/numeric-input-parser.util.ts | Adds a null-safe numeric parser and a helper to replace Formly’s crash-prone numeric parser without DOM access. |
| frontend/src/app/workspace/component/property-editor/operator-property-edit-frame/numeric-input-parser.util.spec.ts | Adds unit tests validating numeric parsing behavior and safe parser replacement semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export function applySafeNumericParser(field: FormlyFieldConfig): void { | ||
| if (field.parsers && field.parsers.length > 0) { | ||
| field.parsers = [value => parseNumericInput(value)]; | ||
| } | ||
| } |
What changes were proposed in this PR?
Fixes typed edits being ignored on integer/number operator property fields (reproduced
on the Limit operator): the field gets stuck and only the +/- steppers work.
Root cause:
@ngx-formly/core's json-schema integer/number parser readsdocument.querySelector('#' + field.id).validity.badInput, assuming the id is on thenative
<input>. ng-zorro'snz-input-numberputs the id on its host element (whichhas no
.validity), so the parser throwsCannot read properties of undefined (reading 'badInput')whenever the parsed value is null (an intermediate state whiletyping). The typed value then never commits.
This replaces that parser, for numeric fields only, with a null-safe parser that does
no DOM access (
applySafeNumericParserinjsonSchemaMapIntercept). The stepper pathwas unaffected and keeps working.
Any related issues, documentation, discussions?
Closes #6054
How was this PR tested?
parseNumericInput(numeric/decimal/negative/whitespace/empty/non-numeric/DOM-safety) and
applySafeNumericParser(replaces the crash-prone parser,null-safe on the clear-field case, leaves non-numeric fields untouched) — 12 tests.
OperatorPropertyEditFrameComponentspec still passes.and the console
badInputTypeError is gone.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.8)