RadMaskedDateTimeInput - Set current month/year automaticly

6 posts, 0 answers
  1. Erik
    Erik avatar
    5 posts
    Member since:
    Jan 2009

    Posted 07 Jan 2013 Link to this post

    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?
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 10 Jan 2013 Link to this post

    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.

  3. DevCraft banner
  4. Erik
    Erik avatar
    5 posts
    Member since:
    Jan 2009

    Posted 11 Jan 2013 Link to this post

    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.
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 16 Jan 2013 Link to this post

    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.

  6. Erik
    Erik avatar
    5 posts
    Member since:
    Jan 2009

    Posted 16 Jan 2013 Link to this post

    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.
  7. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 17 Jan 2013 Link to this post

    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.

Back to Top
DevCraft banner