WindowsCommunityToolkit icon indicating copy to clipboard operation
WindowsCommunityToolkit copied to clipboard

Update TextBoxRegex to use the newer BeforeTextChanging event (SDK 1709)

Open jp-weber opened this issue 4 years ago • 9 comments

Fixes #3628

PR Type

What kind of change does this PR introduce?

Feature

What is the current behavior?

Currently, the characters are checked for validity after they have been entered and set. Therefore, there are various events that currently have to be used to validate the entries for the various modes and to delete them if necessary.

What is the new behavior?

With the change, the values of the input are validated before the input is set and, with the ValidationMode dynamic, these are discarded if the input is not valid.

PR Checklist

Please check if your PR fulfills the following requirements:

  • [ ] Tested code with current supported SDKs
  • [ ] Pull Request has been submitted to the documentation repository instructions. Link:
  • [X] Sample in sample app has been added / updated (for bug fixes / features)
  • [ ] 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)
  • [ ] Contains NO breaking changes

Other information

Are there still things in this regard that I have not taken into account? Due to the internal change, the description in the documentation for dynamic would have to be changed: https://docs.microsoft.com/en-us/dotnet/api/microsoft.toolkit.uwp.ui.extensions.textboxregex.validationmode?view=win-comm-toolkit-dotnet-stable

jp-weber avatar Dec 11 '20 19:12 jp-weber

Thanks jp-weber for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

ghost avatar Dec 11 '20 19:12 ghost

After a few tests so far, I have noticed that one behaviour has changed minimally. If the ValidationMode Dynamic is used and an invalid string is copied into the field, the input is aborted.

In the current version, the entry is deleted until a valid value is reached. If, for example, only characters are accepted in the field and the input is: 123abcd123 => the whole text is deleted abcd123 => only 123 is deleted

The question that now arises for me is this minimal change in behaviour okay?

jp-weber avatar Dec 14 '20 17:12 jp-weber

@jp-weber Thanks for all the work and the PR. Was there any issue open for this PR? If not can you please create one? 😊

Kyaa-dost avatar Dec 14 '20 18:12 Kyaa-dost

@Kyaa-dost okay, I have created the issue that did not exist before and linked it here.

jp-weber avatar Dec 14 '20 21:12 jp-weber

@jp-weber Thank you so much ❤️

Kyaa-dost avatar Dec 14 '20 22:12 Kyaa-dost

Thanks @jp-weber, going to mark as draft for now so we can continue the discussion in the issue a bit first to make sure we get the scenario down.

michael-hawker avatar Dec 15 '20 17:12 michael-hawker

@jamesmcroft I know you've been doing a lot around input validation lately. Would love your thoughts in this space (more details in the linked issue).

I think I'd want to make sure we have unit/interaction tests in this area to define/preserve the functionality we require from the user perspective before we make sweeping changes, eh?

I'm going to move this to 7.1 for now, since there's still questions here.

michael-hawker avatar Feb 18 '21 21:02 michael-hawker

This works well and from a user experience perspective is improved.

One thing I noted from running the sample for this vs the current sample app, in one of the input boxes where this dynamic validation is enabled, if you type a character/digit that is not valid, then type something that is valid, the first character/digit is shifted along by the text input cursor moving back to the start.

E.g. in the numeric only text box, you type 'a12345', the text reads '23451'.

If the first is a valid input, it will work normally.

jamesmcroft avatar Jul 28 '21 08:07 jamesmcroft

Good catch @jamesmcroft with the input 'a12345', I played around a bit last night and implemented a workaround for this, now only the unit tests should be missing.

https://github.com/jp-weber/UWPCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp.UI/Extensions/TextBoxRegEx/TextBoxRegex.cs#L52

There seems to be somehow the problem that when an input is canceled, the start position of the input is shifted. Probably this is a general problem of the BeforeTextChanging event?

jp-weber avatar Jul 30 '21 14:07 jp-weber