This is a migrated thread and some comments may be shown as answers.

RadMaskedDateTimeInput - Set current month/year automaticly

5 Answers 110 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 1
Erik asked on 07 Jan 2013, 09:33 AM
In your raddatetimepicker control you can enter just a day, and the controls sets the current month/year by itself.
Is this possible to to with a RadMaskedDateTimeInput?
I have a scenario with a mask like dd.mm.yyyy and I want the control to fill in the month and year if you just type 7 or 07, the control should show 07.01.2013 by itself.

If this is not possible, how can i clear the control if a user types 7, and set focus to another control?

5 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 10 Jan 2013, 11:12 AM
Hi Erik,

In order to achieve your goal you can use the ValueToTextConverter property of the RadMaskedDateTimeInput control. You have to create a custom converter inherited from the IValueConverter and implement it's Convert() method. This method will be called when the Mask property mark the entered value as valid. This is done when the mask requirements are fulfilled (one of them is to fill all spaces and move the focus away from the control). Hence you have to set the Mask to "dd" in your case. Please take a look at the attached project and let me know if works for you.

Regards,
Pavel R. Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Erik
Top achievements
Rank 1
answered on 11 Jan 2013, 02:06 PM
Thank you for your reply!
Your solution will not work for me. It will work for that specific case, but you cant enter anything else than the day, so if you want to enter a date in another month, you cant do so.
I want to use the mask like dd.MM.yyyy or something like that so you can enter any date, but I miss the "auto month-year" you get from the RadDatePicker.
The reason I need this is because I have created my own DatePickerControl, which is almost simular to the RadDatePicker, but it uses the mask. Is it any other approach to achieve this? My control as it is now is a RadMaskedDateTimeInput, a RadDropdownbutton and a Calender, but the best solution would be to use a RadDatePicker with a mask if that is possible, including the "auto month-year" you get from the RadDatePicker.
0
Tina Stancheva
Telerik team
answered on 16 Jan 2013, 02:00 PM
Hi Erik,

When working with the MaskedInput controls, it's important to have in mind that they process their values based on the defined Mask. That essentially means that the MaskedInput controls, the RadMaskedDateTimeInput included, consider a value entered only when its size and content match the Mask restrictions. This is why when you set a Mask of "dd.MM.yyyy", the MaskedDateTimeInput control expects a value of this type to be entered. And if you only enter the day, the control won't understand this value as a correctly entered value and it won't be able to process it. The ValueChanging/ValueChanged events won't be fired and even if you try to attach a handler for the MaskedDateTimeInput LostFocus event, you'll notice that the Value and Text properties of the control aren't updated - they hold the last valid value of the control until a new valid value is entered.

This is why we previously suggested creating a Mask that only requires a day entrance and then auto-completes the date using the current month and year through a converter.

Also, I am not sure why you needed to create a custom RadDateTimePicker-like control. If the RadDateTimePicker functionality is what you need but you would also like to control the date format, then you can apply a custom culture on the control to set the format of the entered value.

I hope this information will help you better understand the context of the controls and use them to implement your scenario.

All the best,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Erik
Top achievements
Rank 1
answered on 16 Jan 2013, 02:21 PM
I understand all that, but I want to expand the standard RadDateTimePicker with the mask functionality, because its not good enough as it is out of the box. I want the users to be able to enter a complete date including day,month and year without typing the . or / letters. If you have a mask you can ex type 16012013 and the date will be 16.01.2013, as it is now you have to type the . letter.
If the text you see in the radmaskeddatetimeinput was a public value it would be much easier, then I could manipulate the value properly if the user just enter a day value and set focus to another control.
0
Tina Stancheva
Telerik team
answered on 17 Jan 2013, 12:06 PM
Hi Erik,

The text in the RadMaskedDateTime input can be accessed through the Text property, which is a public property. Unfortunately, due to the Mask property restrictions, the Text and Value properties will not be updated until a valid input is received in the control. This is why you won't be able to use these properties to auto-complete the date when the control loses its focus.

However, you can implement the desired behavior in the RadDateTimePicker control by implementing a custom parsing logic as described in this tutorial. You can also take a look at this forum thread where the same issue is discussed and a possible solution is described.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Erik
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Erik
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or