Skip to content

Resolved the OtpInput value mismatch issue for input types text and password.#250

Merged
PaulAndersonS merged 2 commits intomainfrom
OtpInputValueMismatch
Aug 21, 2025
Merged

Resolved the OtpInput value mismatch issue for input types text and password.#250
PaulAndersonS merged 2 commits intomainfrom
OtpInputValueMismatch

Conversation

@KishoreJey
Copy link

@KishoreJey KishoreJey commented Aug 20, 2025

Root Cause of the Issue

The internal logic for the SfOtpInput component's Value property was including non-printable control characters (specifically, null characters like \0) in its string representation. These characters were likely used as internal placeholders for empty OTP cells. When the ValueChanged event was triggered, these control characters were included in the NewValue and OldValue properties of the event arguments. This caused the reported values to be incorrect (e.g., "1a\0\0" instead of "1a"), leading to a data mismatch and unexpected behavior when consuming the event.

Description of Change

  • To resolve this, the OnValuePropertyChanged method has been updated to sanitize the OTP values before the ValueChanged event is raised.
  • The implementation now explicitly filters both the oldValue and newValue strings to remove any control characters.
  • This ensures that the OtpInputValueChangedEventArgs passed to the user contain only the actual visible characters that have been entered.
  • This change guarantees clean and accurate string data in the event, resolving the value mismatch issue for all input types, including Text and Password.

Issues Fixed

Issue : #184

@PaulAndersonS PaulAndersonS requested a review from Copilot August 20, 2025 11:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a value mismatch issue in the SfOtpInput component where control characters (like null characters) were being included in ValueChanged event arguments, causing incorrect reported values. The fix ensures that only visible characters are passed to event handlers for all input types.

  • Removes conditional logic that only sanitized control characters for Number input type
  • Applies control character filtering to all OTP input types (Text, Password, Number)
  • Simplifies the event raising logic by using sanitized values consistently

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

newValueStr = new string(newValueStr.Where(c => !char.IsControl(c)).ToArray());
oldValueStr = new string(oldValueStr.Where(c => !char.IsControl(c)).ToArray());
RaiseValueChangedEvent(otpInput, oldValueStr, newValueStr);
}
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null check for ValueChanged is redundant since the subsequent call uses the null-conditional operator (?.). Consider removing this if statement and just calling RaiseValueChangedEvent directly, as the method already handles null events safely.

Copilot uses AI. Check for mistakes.
@PaulAndersonS
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@PaulAndersonS PaulAndersonS merged commit c908b42 into main Aug 21, 2025
2 checks passed
@PaulAndersonS PaulAndersonS added this to the v1.0.7 milestone Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

4 participants