MD.OFFICE
FAL

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: boolean with numberType: 'default' | 'percentage' | 'currency' in NumberFieldConfig.
  • Legacy Removal: Completely stripped all references to currencyEnabled from the codebase, including interfaces, default configurations, and rendering logic.
  • Service Refinement: Updated DynaformService.createNumberInputElement to rely solely on numberType and 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 percentage type now automatically sets the suffix to % and clears it when switching to other types.

2. Formula Builder Integration

  • Metadata Propagation: Propagated numberType through the formula suggestion system in RightPanelStaticComponent.
  • Automated Formatting: Modified FormulaBuilderComponent to intercept percentage field selections and automatically wrap them as ( @FieldName / 100 ) in the formula input.
  • Suggestion Filtering: Refined the logic to ensure numberType is 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 onNumberTypeChange that 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 outputType system (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 FormulaFieldConfig to hold outputType and outputCurrency. The formula renderer dynamically adjusts the p-inputNumber mode 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 date math 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)] mutated item.numberType before the handler ran, so comparing old vs new was impossible without a temp variable.
  • Fix — Split ngModel: Changed the p-select to [ngModel] + (ngModelChange)="onNumberTypeChange(item, $event)". This means item.numberType is still the old value when the handler fires, and $event is 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 _previousNumberType property on the element JSON by using the intercepted $event value instead.