EasyUI Forum
May 04, 2024, 06:12:09 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: ComboBox and DateBox keyboard nav  (Read 2514 times)
chrwei
Full Member
***
Posts: 219


View Profile Email
« on: December 09, 2020, 09:13:53 AM »

I've worked out how to add this on my own by using $.extend, but it requires that I maintain a copy of part of the core code, and is heavily based on that code so the license doesn't allow sharing or distributing it.  (I don't distribute it, it's for my own use)

ComboBox has up and down handlers for keyboard nav, but it only works when the drop down is open.  I expect it to work when the drop down is closed too, since the basic HTML <select> and desktop apps all do it.

For the Datebox, when the calendar box is open, it navigates by day for left/right and week for up/down.  I also have it have it nav by day when the calendar is closed, but I understand not everyone would want this.

Please add these additional keyboard nav features.

Since my datebox code isn't based on your code, I'll provide that here.  it's simple and somewhat obvious, so use it as you wish.

Code:
(function($){
  $.extend($.fn.datebox.defaults.keyHandler, {
    up: function (e) {
      var v = new Date();
      if($(e.data.target).datebox('getValue') != "") {
        v = new Date(Date.parse($(e.data.target).datebox('getValue')));
      }
      if ($(e.data.target).datebox('panel').parent().css('display') == "none") {
        v.setDate(v.getDate() + 1);
      } else {
        v.setDate(v.getDate() - 7);
      }
      $(e.data.target).datebox('setValue', v.format("shortDate"));
    },
    down: function (e) {
      var v = new Date();
      if($(e.data.target).datebox('getValue') != "") {
        v = new Date(Date.parse($(e.data.target).datebox('getValue')));
      }
      if ($(e.data.target).datebox('panel').parent().css('display') == "none") {
        v.setDate(v.getDate() - 1);
      } else {
        v.setDate(v.getDate() + 7);
      }
      $(e.data.target).datebox('setValue', v.format("shortDate"));
    },
    left: function (e) {
      var v = new Date();
      if($(e.data.target).datebox('getValue') != "") {
        v = new Date(Date.parse($(e.data.target).datebox('getValue')));
      }
      v.setDate(v.getDate() - 1);
      $(e.data.target).datebox('setValue', v.format("shortDate"));
    },
    right: function (e) {
      var v = new Date();
      if($(e.data.target).datebox('getValue') != "") {
        v = new Date(Date.parse($(e.data.target).datebox('getValue')));
      }
      v.setDate(v.getDate() + 1);
      $(e.data.target).datebox('setValue', v.format("shortDate"));
    }
  });
})(jQuery);
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!