[TestMethod] public void IsEqualTest() { Assert.IsTrue(Decimals.IsEqual(decimal.MinValue, decimal.MinValue)); Assert.IsTrue(Decimals.IsEqual(decimal.MaxValue, decimal.MaxValue)); Assert.IsTrue(Decimals.IsEqual(d1, d1)); Assert.IsFalse(Decimals.IsEqual(d1, d2)); }
/// <inheritdoc/> public override async Task SetParametersAsync(ParameterView parameters) { var decimalsChanged = parameters.TryGetValue(nameof(Decimals), out int decimals) && !Decimals.IsEqual(decimals); if (Rendered && decimalsChanged) { ExecuteAfterRender(async() => await JSRunner.UpdateNumericEdit(ElementRef, ElementId, new { Decimals = new { Changed = decimalsChanged, Value = decimals }, })); } // This make sure we know that Min or Max parameters are defined and can be checked against the current value. // Without we cannot determine if Min or Max has a default value when TValue is non-nullable type. MinDefined = parameters.TryGetValue <TValue>(nameof(Min), out var min); MaxDefined = parameters.TryGetValue <TValue>(nameof(Max), out var max); await base.SetParametersAsync(parameters); if (ParentValidation != null) { if (parameters.TryGetValue <Expression <Func <TValue> > >(nameof(ValueExpression), out var expression)) { await ParentValidation.InitializeInputExpression(expression); } if (parameters.TryGetValue <string>(nameof(Pattern), out var pattern)) { // make sure we get the newest value var value = parameters.TryGetValue <TValue>(nameof(Value), out var inValue) ? inValue : InternalValue; await ParentValidation.InitializeInputPattern(pattern, value); } await InitializeValidation(); } }
/// <inheritdoc/> public override async Task SetParametersAsync(ParameterView parameters) { if (Rendered) { var decimalsChanged = isIntegerType ? false : parameters.TryGetValue <int>(nameof(Decimals), out var paramDecimals) && !Decimals.IsEqual(paramDecimals); var decimalSeparatorChanged = parameters.TryGetValue <string>(nameof(DecimalSeparator), out var paramDecimalSeparator) && !DecimalSeparator.IsEqual(paramDecimalSeparator); var alternativeDecimalSeparatorChanged = parameters.TryGetValue <string>(nameof(AlternativeDecimalSeparator), out var paramAlternativeDecimalSeparator) && !AlternativeDecimalSeparator.IsEqual(paramAlternativeDecimalSeparator); var groupSeparatorChanged = parameters.TryGetValue <string>(nameof(GroupSeparator), out var paramGroupSeparator) && !GroupSeparator.IsEqual(paramGroupSeparator); var groupSpacingChanged = parameters.TryGetValue <string>(nameof(GroupSpacing), out var paramGroupSpacing) && !GroupSpacing.IsEqual(paramGroupSpacing); var currencySymbolChanged = parameters.TryGetValue <string>(nameof(CurrencySymbol), out var paramCurrencySymbol) && !CurrencySymbol.IsEqual(paramCurrencySymbol); var currencySymbolPlacementChanged = parameters.TryGetValue <CurrencySymbolPlacement>(nameof(CurrencySymbolPlacement), out var paramCurrencySymbolPlacement) && !CurrencySymbolPlacement.IsEqual(paramCurrencySymbolPlacement); var roundingMethodChanged = parameters.TryGetValue <NumericRoundingMethod>(nameof(RoundingMethod), out var paramRoundingMethod) && !RoundingMethod.IsEqual(paramRoundingMethod); var minChanged = parameters.TryGetValue <TValue>(nameof(Min), out var paramMin) && !Min.IsEqual(paramMin); var maxChanged = parameters.TryGetValue <TValue>(nameof(Max), out var paramMax) && !Max.IsEqual(paramMax); var minMaxLimitsOverrideChanged = parameters.TryGetValue <NumericMinMaxLimitsOverride>(nameof(MinMaxLimitsOverride), out var paramMinMaxLimitsOverride) && !MinMaxLimitsOverride.IsEqual(paramMinMaxLimitsOverride); var selectAllOnFocusChanged = parameters.TryGetValue <bool>(nameof(SelectAllOnFocus), out var paramSelectAllOnFocus) && !SelectAllOnFocus.IsEqual(paramSelectAllOnFocus); var allowDecimalPaddingChanged = parameters.TryGetValue <NumericAllowDecimalPadding>(nameof(AllowDecimalPadding), out var paramAllowDecimalPadding) && !AllowDecimalPadding.IsEqual(paramAllowDecimalPadding); var alwaysAllowDecimalSeparatorChanged = parameters.TryGetValue <bool>(nameof(AlwaysAllowDecimalSeparator), out var paramAlwaysAllowDecimalSeparator) && !AlwaysAllowDecimalSeparator.IsEqual(paramAlwaysAllowDecimalSeparator); var modifyValueOnWheelChanged = parameters.TryGetValue <bool>(nameof(ModifyValueOnWheel), out var paramModifyValueOnWheel) && !ModifyValueOnWheel.IsEqual(paramModifyValueOnWheel); var wheelOnChanged = parameters.TryGetValue <NumericWheelOn>(nameof(WheelOn), out var paramWheelOn) && !WheelOn.IsEqual(paramWheelOn); if (decimalsChanged || decimalSeparatorChanged || alternativeDecimalSeparatorChanged || groupSeparatorChanged || groupSpacingChanged || currencySymbolChanged || currencySymbolPlacementChanged || roundingMethodChanged || minChanged || maxChanged || selectAllOnFocusChanged || allowDecimalPaddingChanged || alwaysAllowDecimalSeparatorChanged || modifyValueOnWheelChanged) { ExecuteAfterRender(async() => await JSModule.UpdateOptions(ElementRef, ElementId, new { Decimals = new { Changed = decimalsChanged, Value = GetDecimals() }, DecimalSeparator = new { Changed = decimalSeparatorChanged, Value = paramDecimalSeparator }, AlternativeDecimalSeparator = new { Changed = alternativeDecimalSeparatorChanged, Value = paramAlternativeDecimalSeparator }, GroupSeparator = new { Changed = groupSeparatorChanged, Value = paramGroupSeparator }, GroupSpacing = new { Changed = groupSpacingChanged, Value = paramGroupSpacing }, CurrencySymbol = new { Changed = currencySymbolChanged, Value = paramCurrencySymbol }, CurrencySymbolPlacement = new { Changed = currencySymbolPlacementChanged, Value = paramCurrencySymbolPlacement.ToCurrencySymbolPlacement() }, RoundingMethod = new { Changed = roundingMethodChanged, Value = paramRoundingMethod.ToNumericRoundingMethod() }, AllowDecimalPadding = new { Changed = allowDecimalPaddingChanged, Value = paramAllowDecimalPadding.ToNumericDecimalPadding() }, AlwaysAllowDecimalSeparator = new { Changed = alwaysAllowDecimalSeparatorChanged, Value = paramAlwaysAllowDecimalSeparator }, Min = new { Changed = minChanged, Value = paramMin }, Max = new { Changed = maxChanged, Value = paramMax }, MinMaxLimitsOverride = new { Changed = minMaxLimitsOverrideChanged, Value = paramMinMaxLimitsOverride }, SelectAllOnFocus = new { Changed = selectAllOnFocusChanged, Value = paramSelectAllOnFocus }, ModifyValueOnWheel = new { Changed = modifyValueOnWheelChanged, Value = paramModifyValueOnWheel }, WheelOn = new { Changed = wheelOnChanged, Value = paramWheelOn }, })); } var valueChanged = parameters.TryGetValue <TValue>(nameof(Value), out var paramValue) && !Value.IsEqual(paramValue); if (valueChanged) { ExecuteAfterRender(async() => await JSModule.UpdateValue(ElementRef, ElementId, paramValue)); } } // This make sure we know that Min or Max parameters are defined and can be checked against the current value. // Without we cannot determine if Min or Max has a default value when TValue is non-nullable type. MinDefined = parameters.TryGetValue <TValue>(nameof(Min), out var min); MaxDefined = parameters.TryGetValue <TValue>(nameof(Max), out var max); await base.SetParametersAsync(parameters); if (ParentValidation != null) { if (parameters.TryGetValue <Expression <Func <TValue> > >(nameof(ValueExpression), out var expression)) { await ParentValidation.InitializeInputExpression(expression); } if (parameters.TryGetValue <string>(nameof(Pattern), out var pattern)) { // make sure we get the newest value var value = parameters.TryGetValue <TValue>(nameof(Value), out var inValue) ? inValue : InternalValue; await ParentValidation.InitializeInputPattern(pattern, value); } await InitializeValidation(); } }
/// <inheritdoc/> public override async Task SetParametersAsync(ParameterView parameters) { var decimalsChanged = parameters.TryGetValue(nameof(Decimals), out int decimals) && !Decimals.IsEqual(decimals); if (Rendered && decimalsChanged) { ExecuteAfterRender(async() => await JSRunner.UpdateNumericEdit(ElementRef, ElementId, new { Decimals = new { Changed = decimalsChanged, Value = decimals }, })); } await base.SetParametersAsync(parameters); if (ParentValidation != null) { if (parameters.TryGetValue <Expression <Func <TValue> > >(nameof(ValueExpression), out var expression)) { await ParentValidation.InitializeInputExpression(expression); } if (parameters.TryGetValue <string>(nameof(Pattern), out var pattern)) { // make sure we get the newest value var value = parameters.TryGetValue <TValue>(nameof(Value), out var inValue) ? inValue : InternalValue; await ParentValidation.InitializeInputPattern(pattern, value); } await InitializeValidation(); } }