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

Unable to prevent event propagation with OnKeyPress

1 Answer 105 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 04 Aug 2015, 04:55 PM

 I'm trying to add JavaScript to allow users to select today's date by pressing "T" key.  I've copied the following code from elsewhere in this forum.  Sorry, I cannot find original post.   The below code does exactly what what we want except the t is showing up in the text.  For example, "8/4/2015t" is what is being displayed.  

 Is there a way to prevent key press from being propagated?  Below is demo code that I'm working with.

<telerik:RadDatePicker ID="DatePicker1" runat="server" >
     <DateInput ClientEvents-OnKeyPress="DateTextBoxKeyPress"/>
</telerik:RadDatePicker>

 

function DateTextBoxKeyPress(sender, args) {
 
    var s1 = args.get_keyCharacter().toUpperCase();
 
    if (s1 === "T") {
 
        var datePicker = sender;
        var date = new Date();
 
        date.setDate(date.getDate());
        datePicker.set_selectedDate(date);
    }
}

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 07 Aug 2015, 02:42 PM
Hello Thomas,

You can achieve this requirement by adding args.set_cancel(true); to the end of the function.
That should do the trick. Please give it a try and let me know if it works for you.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DatePicker
Asked by
Thomas
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or