Skip to content

Commit 31bf71f

Browse files
author
msftbot[bot]
authored
fixes for case adding data at the end of the textbox (#3338)
## Fixes #3335 When using the TextBoxMask extension, the TextBox text not updated if the text with the same string length changes, unless if the string length is less than the current Text length. ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more that apply to this PR. --> - Bugfix <!-- - Feature --> <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? Example, a TextBox with Mask `99:59:59` where cutom mask 5:[0-5], if the current Text is 10:20:30 and we update with 20:30:40, the Text did not changed/updated. The UI will show the same '10:20:30' because of this code: `textbox.Text = oldText;` ## What is the new behavior? Example, if the current Text is 10:20:30 and we update with 20:30:40, the Text changed/updated. The fix is to let the text updated on this regards and no other behavior changes. ## PR Checklist Please check if your PR fulfills the following requirements: - [ ] Tested code with current [supported SDKs](../readme.md#supported) - [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link --> - [ ] Sample in sample app has been added / updated (for bug fixes / features) - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets) - [ ] Tests for the changes have been added (for bug fixes / features) (if applicable) - [ ] Header has been added to all new source files (run *build/UpdateHeaders.bat*) - [X] Contains **NO** breaking changes <!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. Please note that breaking changes are likely to be rejected. --> ## Other information
2 parents b20befb + a1e8dd6 commit 31bf71f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Microsoft.Toolkit.Uwp.UI/Extensions/TextBoxMask/TextBoxMask.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ private static void Textbox_TextChanging(TextBox textbox, TextBoxTextChangingEve
300300
// case adding data at the end of the textbox
301301
if (oldSelectionStart >= oldText.Length && !isDeleteOrBackspace)
302302
{
303-
textbox.Text = oldText;
303+
textbox.Text = textbox.Text.Substring(0, oldText.Length);
304304
if (oldText.Length >= 0)
305305
{
306306
textbox.SelectionStart = oldText.Length;
@@ -327,6 +327,7 @@ private static void Textbox_TextChanging(TextBox textbox, TextBoxTextChangingEve
327327
if (string.IsNullOrEmpty(textbox.Text))
328328
{
329329
textbox.Text = displayText;
330+
return;
330331
}
331332
else
332333
{

0 commit comments

Comments
 (0)