2026-03-11 - Dynaforms Enhancements: numberType & Formula Integration
Today's work focused on replacing the legacy currencyEnabled toggle with a unified numberType property and integrating it into the formula builder for automated percentage calculations.
Achievements
1. Core Configuration & numberType Implementation
- Property Transition: Replaced
currencyEnabled: booleanwithnumberType: 'default' | 'percentage' | 'currency'inNumberFieldConfig. - Legacy Removal: Completely stripped all references to
currencyEnabledfrom the codebase, including interfaces, default configurations, and rendering logic. - Service Refinement: Updated
DynaformService.createNumberInputElementto rely solely onnumberTypeand removed backward compatibility fallbacks. - UI Simplification: Removed the redundant "Enable Currency" toggle from the property panel. The currency dropdown now appears dynamically based on the selected
numberType. - Suffix Automation: Selection of
percentagetype now automatically sets the suffix to%and clears it when switching to other types.
2. Formula Builder Integration
- Metadata Propagation: Propagated
numberTypethrough the formula suggestion system inRightPanelStaticComponent. - Automated Formatting: Modified
FormulaBuilderComponentto intercept percentage field selections and automatically wrap them as( @FieldName / 100 )in the formula input. - Suggestion Filtering: Refined the logic to ensure
numberTypeis only attached to actual number fields, keeping formula fields and matrix cells clean.
3. Safety Guards & Edge Cases
- Reference Guard: Implemented a warning toast in
onNumberTypeChangethat alerts the user if they modify the type of a field already referenced in existing formulas. - Architectural Decision: Decided against auto-reverting formula strings when types change to avoid potential corruption due to the lack of an AST-based parser for raw math strings.
4. Formula Output Type & Currency Propagation
- Validation-Time Binding: Designed an
outputTypesystem (decimal|currency) to dictate how formulas should render their results natively, computed during the formula validation phase. - Strict Currency Math Enforcement: If a formula references a currency field, the builder now mandates that all referenced fields are currency fields with the identical currency code to maintain precision; otherwise, formula validation fails.
- Dynamic Formatting: Extended the
FormulaFieldConfigto holdoutputTypeandoutputCurrency. The formula renderer dynamically adjusts thep-inputNumbermode based on these configs to accurately display numbers or local currencies (like₹ 1,500.00) based strictly on their internal mathematical lineage. - Scope Definition: Explicitly deferred support for
datemath rendering to future iterations to keep this release cleanly focused on decimals, percentages, and currencies.
5. Symmetric numberType Guard & ngModel Refactoring
- Bug Found: The warning toast was only firing when switching away from percentage, not into it — meaning if a field already used in a formula was switched to percentage, users got no indication that the existing
( / 100 )wrapping was missing. - Root Cause of Mutation Bug:
[(ngModel)]mutateditem.numberTypebefore the handler ran, so comparing old vs new was impossible without a temp variable. - Fix — Split ngModel: Changed the
p-selectto[ngModel]+(ngModelChange)="onNumberTypeChange(item, $event)". This meansitem.numberTypeis still the old value when the handler fires, and$eventis the new value. - Symmetric Guard: Updated the condition to
oldNumberType !== newNumberType && percentageInvolved, which fires for both "to percentage" and "from percentage" transitions on referenced fields. - Direction-Aware Toast: The message dynamically says "Changing its type to percentage" or "from percentage" so it's always clear which direction triggered the warning.
- No JSON Pollution: Avoids any temp
_previousNumberTypeproperty on the element JSON by using the intercepted$eventvalue instead.