Skip to content

Commit 0607c7c

Browse files
committed
Resolved the ValueChanged event issue in SfOtpInput.
1 parent e1011a1 commit 0607c7c

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

maui/src/OtpInput/SfOtpInput.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -862,12 +862,28 @@ static void OnValuePropertyChanged(BindableObject bindable, object oldValue, obj
862862
return;
863863
}
864864

865-
if (otpInput.ValueChanged != null)
866-
{
867-
RaiseValueChangedEvent(otpInput, oldValue?.ToString() ?? string.Empty, newValue?.ToString() ?? string.Empty);
865+
string newValueStr = newValue?.ToString() ?? string.Empty;
866+
string oldValueStr = oldValue?.ToString() ?? string.Empty;
867+
868+
if (otpInput.Type == OtpInputType.Number)
869+
{
870+
newValueStr = new string(newValueStr.Where(c => !char.IsControl(c)).ToArray());
871+
oldValueStr = new string(oldValueStr.Where(c => !char.IsControl(c)).ToArray());
872+
}
873+
874+
if (otpInput.ValueChanged != null)
875+
{
876+
if (otpInput.Type == OtpInputType.Number)
877+
{
878+
RaiseValueChangedEvent(otpInput, oldValueStr, newValueStr);
879+
}
880+
else
881+
{
882+
RaiseValueChangedEvent(otpInput, oldValue?.ToString() ?? string.Empty, newValue?.ToString() ?? string.Empty);
883+
}
868884
}
869-
870-
otpInput.UpdateValue(bindable, newValue?? string.Empty);
885+
886+
otpInput.UpdateValue(bindable, newValue?? string.Empty);
871887
}
872888
}
873889

0 commit comments

Comments
 (0)