Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
110
xamMaskedEditor - bug when masking a value with embedded spaces
posted

So, I think this is a bug in the xamMaskedEditor, but if there are options that I did not consider please let me know.

Our use-case: We have values that we need to display/capture that are basically "triplets": three distinct strings, saved as one string in the DB and presented to the user as a slash "/" delimited value. The persisted values do not contain the slashes,  it is only for UI presentation. So we are using the xamMaskedEditor and setting its Mask property to "CCC/CCC/CCC" as one example. The "C" character in the mask allows for basically any character, and is not required. The user is free then to enter the strings in whatever format is required by their business rules, each section can contain spaces at any position. So, "123/456/789" is valid as is "1 3/ 56/  9".

The problems come when a space is present in the source string in a position that would fall just after a literal character (the "/" in this case). So the bad positions in this case are indexes 4 and 8. As the mask is parsed and applied in the SetText method of the xamMaskedEditor, when it reaches the first literal character "/" in the mask, the next value in the input string is a space. It looks for a match between the two and not finding it, next looks to see if the current input character is a prompt or padding character, which it is because it is a space. It then skips that character and moves on.

Some improvement was found by setting these values on the editor:

 DisplayMode="IncludeBoth" (also tried IncludeLiteralsWithPadding)

 DataMode="IncludePromptChars"

 IsAlwaysInEditMode="True" (even with changes to the DisplayMode, when tabbing out of the field, the mask is reapplied and the format is again broken, so the only way I found to prevent was to have the control always be in edit mode)

However, this only worked to a point, when the value being loaded from the database contained the embedded spaces the initial load/mask would fail and alter the string. 

I have worked around this for now by adding custom value converter to the mix that "pre-masks" the data coming from the source, so that the masking logic from the editor will not fail.

I have attached a sample project to duplicate this issue. Changes to source text TextBox willl cause the xamMaskedEditor to reload the text and reapply the mask.

Thanks for any feedback.

Andreas

 

MaskedEditorBug.zip
Parents
No Data
Reply
  • 5600
    Offline posted

    Hello,

    If you add the "/" char in the source text which comes from DB then the text is displayed correctly.

    So one way to overcome this is before you set the source text to xamMaskedEditor - get the source text and according to mask to put "/" on the right location. The client will store the source text without "/" char - you will be responsible to put "/" char in the right location.

    If you have any questions do not hesitate to ask.

    Regards,

    Anastas 

Children