Unable to prevent event propagation with OnKeyPress

2 posts, 0 answers
  1. Thomas
    Thomas avatar
    3 posts
    Member since:
    Nov 2013

    Posted 04 Aug 2015 Link to this post

     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);
        }
    }

  2. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 07 Aug 2015 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top