Using tabbing in jeditable fields in datatables
Asked Answered
G

1

0

Right now I have a datatable, some fields are editable, some are not. I have the following code (taken from tabbing between jeditable fields in a table):

$('#table .select').bind('keydown', function(evt) {
            if(evt.keyCode==9) {
                console.log("next");
                var nextBox='';
                var currentBoxIndex=$("#table .select").index(this);
                console.log("currentBoxIndex",currentBoxIndex);
                 if (currentBoxIndex == ($("#table .select").length-1)) {
                       nextBox=$("#table .select:first");         //last box, go to first
                       console.log("nextBox", nextBox);
                   } else {
                        nextBox=$("#table .select").eq(currentBoxIndex+1);    //Next box in line
                        console.log("nextBox", nextBox);
                   }
                $(this).find("#table  .select").blur();
                $(nextBox).click();  //Go to assigned next box
                return false;           //Suppress normal tab
            };
            }); 

This works great for tabbing to each editable field! Except one issue: I need to be able to tab to the field, select a value from a dropdown in the editable field, and then be able to tab. Right now I can tab through each one if I don't change the value in the field. If I change the value, the tabbing will stop and I have to re-click on the next field. Help?

I'm using:

datatables - http://datatables.net/

Bootstrap

jquery jeditable

Ginni answered 24/7, 2014 at 13:27 Comment(0)
G
0

I found the solution.

        $('#table.select').bind('keydown', function(evt) {
                if(evt.keyCode === 9) {
                    console.log("next");
                    var nextBox = '';
                    var currentBoxIndex = $("#table.select").index(this);
                    console.log("currentBoxIndex",currentBoxIndex);
                    var showDropdown = function (element) {
                        var event;
                        event = document.createEvent('MouseEvents');
                        event.initMouseEvent('mousedown', true, true, window);
                        element.dispatchEvent(event);
                    };
                     if (currentBoxIndex === ($("#table.select").length-1)) {
                           nextBox = $("#table.select:first");         //last box, go to first   
                        showDropdown($(nextBox).get( 0 ));   
                       } else {
                            nextBox = $("#table.select").eq(currentBoxIndex+1);    //Next box in line                         
                            console.log("nextBox", nextBox);    
                            showDropdown($(nextBox).get( 0 ));   
                       }
                    $(this).find("#table.select").blur();                                                     
                    $(nextBox).click();  //Go to assigned next box                                      
                    return false;           //Suppress normal tab
                }
            }); 
Ginni answered 28/7, 2014 at 15:8 Comment(1)
I have found the solution for .select as shown above...however I cannot find a solution for mixed .input and .select.Ginni

© 2022 - 2024 — McMap. All rights reserved.