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

Can't change AM/PM from keyboard

3 Answers 61 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Davide
Top achievements
Rank 1
Davide asked on 02 Oct 2014, 02:04 PM
I'm trying to use the RadMaskedDateTimeInput control, using a mask of "g", which provides date and time input with the AM/PM indicator. The AM/PM indicator can be changed using the up/down arrows when SpinMode is enabled but there is no way to change the AM/PM value using the keyboard. Do you have any solution or it is impossible for this component to do this?

Thx in advance

Davide

3 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 06 Oct 2014, 12:22 PM
Hi,

Could you please clarify what you have in mind when you say:"The AM/PM indicator can be changed using the up/down arrows when SpinMode is enabled"? Which arrows you refer to?

Also, you are allowed to use the arrow keys of the keyboard to change the AP/PM selector. You can see this behavior in our QSF demo after changing the Mask to "g".

Regards,
Pavel R. Pavlov
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Davide
Top achievements
Rank 1
answered on 06 Oct 2014, 12:33 PM
Hi Pavel ... 

In the RadMaskedDateTimeInput i'm displaying only the time as shown in the image 

For the hours, minutes and seconds i can edit them  but this cannot be done for the AM/PM value. I was asking if there is any way to be able to set this value from the keyboard typing A o P

Thx in advance

Davide




0
Pavel R. Pavlov
Telerik team
answered on 07 Oct 2014, 12:59 PM
Hi Davide,

In order to change the AM with PM when the "p" key is pressed you can do these steps:
1. Subscribe to the KeyDown event of the control
2. Add 12 hours to the current Value
If you need the opposite, you can subtract 12 hours when the "a" key is pressed.

You can use this code as starting point:

private void RadMaskedDateTimeInput_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.A)
    {
        DateTime fullValue = (DateTime)(sender as RadMaskedDateTimeInput).Value;
        if (fullValue.Hour >= 12)
        {
            (sender as RadMaskedDateTimeInput).Value = new DateTime(fullValue.Year, fullValue.Month, fullValue.Day, fullValue.Hour - 12, fullValue.Minute, fullValue.Second);
        }
    }
    if (e.Key == Key.P)
    {
        DateTime fullValue = (DateTime)(sender as RadMaskedDateTimeInput).Value;
        if (fullValue.Hour <= 12)
        {
            (sender as RadMaskedDateTimeInput).Value = new DateTime(fullValue.Year, fullValue.Month, fullValue.Day, fullValue.Hour + 12, fullValue.Minute, fullValue.Second);
        }
    }
}


Regards,
Pavel R. Pavlov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

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