Skip to content

Commit 040f0f1

Browse files
committed
updated the changes.
1 parent 2da97e5 commit 040f0f1

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

maui/src/OtpInput/SfOtpInput.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -939,12 +939,7 @@ static void OnValuePropertyChanged(BindableObject bindable, object oldValue, obj
939939
string oldValueStr = oldValue?.ToString() ?? string.Empty;
940940
newValueStr = new string(newValueStr.Where(c => !char.IsControl(c)).ToArray());
941941
oldValueStr = new string(oldValueStr.Where(c => !char.IsControl(c)).ToArray());
942-
943-
if (otpInput.ValueChanged != null)
944-
{
945-
RaiseValueChangedEvent(otpInput, oldValueStr, newValueStr);
946-
}
947-
942+
RaiseValueChangedEvent(otpInput, oldValueStr, newValueStr);
948943
otpInput.UpdateValue(bindable, newValue ?? string.Empty);
949944
}
950945
}
@@ -959,7 +954,6 @@ static void OnLengthPropertyChanged(BindableObject bindable, object oldValue, ob
959954
{
960955
if (bindable is SfOtpInput otpInput && newValue is double newLength && oldValue is double oldLength)
961956
{
962-
963957
if (newLength <= 0)
964958
{
965959
newLength = oldLength;

maui/tests/Syncfusion.Maui.Toolkit.UnitTest/Editors/SfOtpInputUnitTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,37 @@ public void RaiseValueChangedEvent_ShouldTrigger_ValueChangedEvent()
474474
Assert.True(eventTriggered);
475475
}
476476

477+
[Theory]
478+
[InlineData(OtpInputType.Number, "12", "12")]
479+
[InlineData(OtpInputType.Text, "ab", "ab")]
480+
[InlineData(OtpInputType.Password, "xy", "xy")]
481+
public void ValueChangedEvent_WithPartialInput_DoesNotContainNullCharacters(OtpInputType type, string input, string expected)
482+
{
483+
// Arrange
484+
var otpInput = new SfOtpInput
485+
{
486+
Length = 4,
487+
Type = type
488+
};
489+
string? newValueFromEvent = null;
490+
string? oldValueFromEvent = null;
491+
otpInput.ValueChanged += (sender, e) =>
492+
{
493+
newValueFromEvent = e.NewValue;
494+
oldValueFromEvent = e.OldValue;
495+
};
496+
// Act
497+
otpInput.Value = input;
498+
// Assert
499+
Assert.Equal(expected, newValueFromEvent);
500+
Assert.Equal(string.Empty, oldValueFromEvent);
501+
if (newValueFromEvent != null)
502+
{
503+
Assert.DoesNotContain('\0', newValueFromEvent!);
504+
}
505+
}
506+
507+
477508
#endregion
478509

479510
#region Public Methods

0 commit comments

Comments
 (0)