Completed
Last Updated: 10 Oct 2018 10:39 by ADMIN
ADMIN
Martin Ivanov
Created on: 05 Jan 2018 15:11
Category: MaskedInput
Type: Bug Report
2
MaskedInput: The 'hh:mm:ss.f' Mask value of RadMaskedDateTimeInput is coerced wrong
This leads to a wrong value displayed in the masked input. The mask is always coerced to "hh:mm:ss.ff". An additional, 'f' is added to the mask. Probably, this will happen also if you have a single letter on another position in the mask.

To work this around you can create a custom masked input control and override its CoerceTextOverride() method. There you can implement some logic that replaces the wrong milliseconds text. Here is an example in code:

public class CustomMaskedDateTimeInput : RadMaskedDateTimeInput
{
	protected override string CoerceTextOverride(ref int selectionStart)
	{
		var text = base.CoerceTextOverride(ref selectionStart);
		if (this.Value.HasValue && 
			this.Mask != null && 
			this.Mask.Contains("hh:mm:ss.f"))
		{
			
			int millisecondsAllowedLength = GetAllowedMillisecondsLength(this.Mask); // example: .ff means that there are 2 allowed millisecond chars
			int millisecondsMaxLength = 3; // max = 999

			var milliseconds = this.Value.Value.Millisecond.ToString(); // the original milliseconds give from the value
			var zeroesCount = millisecondsMaxLength - milliseconds.Length; // how many zeroes should be append before the millseconds string value

			milliseconds = new string('0', zeroesCount) + milliseconds; // append the zeroes

			// apply the milliseconds restriction given by the Mask (.ff - two symbols)
			if (milliseconds.Length > millisecondsAllowedLength)
			{
				int charsToRemoveCount = milliseconds.Length - millisecondsAllowedLength;
				for (int i = 0; i < charsToRemoveCount; i++)
				{
					milliseconds = milliseconds.Remove(milliseconds.Length - 1, 1);
				}
			}                

			// replace the default parsed millseconds part of the string with the custom milliseconds
			var millisecondsIndex = text.LastIndexOf(".") + 1;
			text = text.Remove(millisecondsIndex, millisecondsMaxLength - millisecondsAllowedLength);
			text = text.Insert(millisecondsIndex, milliseconds);
		}

		return text;
	}

	private int GetAllowedMillisecondsLength(string mask)
	{
		int length = 0;
		var millisecondsIndex = mask.LastIndexOf(".") + 1;
		if (millisecondsIndex != -1)
		{
			length = mask.Length - millisecondsIndex;
		}            
		return length;
	}
}
3 comments
ADMIN
Ralitsa
Posted on: 10 Oct 2018 10:39
Hi,

The fix will be available in our next official version – R3 2018 SP1, scheduled for 17-th October 2018 (Wednesday).

Best regards,
Ralitsa Kumanova
ADMIN
Sia
Posted on: 20 Mar 2018 15:25
Hello Shelly, 

Thank you for the provided details, we will take them into consideration when we implement a fix for the reported bug. Once we start to work on it the feedback item's status will be changed to "In Development".

Regards, 
Sia 
Shelly
Posted on: 05 Jan 2018 16:32
Yes, I have confirmed that the same issue occurs using other single letters.
M is coerced to MM, y is coerced to yy, d is coerced to dd
For example,
M, yyyy becomes 1, 2018 instead of January 04, 2018
y-ddd becomes 18-Thur instead of January, 2018-Thur
d-ddd becomes 4-Thur instead of 01/04/2018-Thur