New
Last Updated: 11 May 2016 13:20 by ADMIN
Imported User
Created on: 04 Feb 2015 16:05
Category: Date/Time Pickers
Type: Feature Request
1
Add an event that is triggered before attempting to read the value from the input.
In a filter input field I had one blur event
to fix a entered date string.
It wasn't called if the users hit "Enter" instead of cliking the Filter button or hitting TAB which
would cause a blur event.

T. Tsonev asked me to post this to "UserVoice portal":
Maybe an event that is triggered before attempting to read the value from the input.
This will consolidate both handlers in your case.


Below are the two handlers to fix an input field if a blur or Enter key is done/hit:

---

If an input field is changed and the user does a blur (TAB or clicks filter button) after
entering a date
or
hits the enter key without doing a blur.
the FixDate function is called and input field is changed
before the filter popup is submitted
and the Filter works if a date like this is entered:
11/9/2004 0:0
FixDate canges to:
11/9/2004 12:00 AM.

Below is the code I changed:
See the sections with "Fix "
comments.

Maybe they need a on "blurOrEnter"
event so you don’t need to make two tests?  (((, or an event that is triggered before attempting to read the value from the input)))
...
               // Fix - Modified to call a FixDate function.
               // Test for a blur (ie: click or tab to another widget and leave the input field)
               // NOTE: blur doesn't happen when the enter key is hit
               $("[data-role=datetimepicker]").on("blur", function()
               {
                    var element = $(this);
                    FixDate(element);
               });
     
               // Fix - Modified to handle the "Enter" key
               //       and call the FixDate function
               //       to modify the input field from "11/9/2004 0:0" to 11/9/2004 12:00 AM"
               //       before the form is submitted.
               //       This makes the filter work when the enter key is hit
               //       which doesn't cause a blur to happen.
               $("[data-role=datetimepicker]").on("keydown", function(e)
               {
                    // Test for Enter key
                    if (e.keyCode == 13)
                    {
                         var element = $(this);
                         FixDate(element);
                    }
               });
          }
     });

     // Change the date in the filter input field by using 
     // Datej Date.parse.
     // This will change strings like: "0:0" 
     // To: "1/29/2015 12:00 AM"
     // and allow the filter to work
     function FixDate(element) 
     {
          // Get element for datetimepicker
          //var element = $(this);
          // Get widget for datetimepicker
          var widget = element.data("kendoDateTimePicker");

          // See if element has changed
          if (element.val())
          { 
               // Set Text of widget to a Datejs string date from the elements text
               // IE: 11/9/2004 0.0 will be 11/9/2004 12:00 AM
               widget.value(Date.parse(element.val()));

               // Fix by T. Tsonev 01/26/2015
               // make a change happend so new text is used.
               // ie: Use "11/9/2004 12:00 AM" instead of "11/9/2004 0:0"
               widget.trigger("change");
          }
     }

...

---
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments