Skip to content

Instantly share code, notes, and snippets.

@buixuanhai
Last active May 30, 2017 12:41
Show Gist options
  • Save buixuanhai/ff4b29a211df3bcf47fce77372b89cca to your computer and use it in GitHub Desktop.
Save buixuanhai/ff4b29a211df3bcf47fce77372b89cca to your computer and use it in GitHub Desktop.
Javascript keydown Độ

Cái này là ul của AutoComplete sinh ra, mặc đinh có display là none

<ul id="ui-id-1" tabindex="0" class="ui-menu ui-widget ui-widget-content ui-autocomplete ui-front" style="display: none; top: 32px; left: 50.6875px; width: 197px;"><li class="ui-menu-item"><div id="ui-id-3" tabindex="-1" class="ui-menu-item-wrapper">ActionScript</div></li></ul>
 $(tr).find('input.form-control').keydown(function (e) {
 
                // Select cái ul của autocomplete, nếu có kết quả khác null thì mới thực hiện mấy cái dưới
                var ul = $(".ui-autocomplete").filter(function() { return $(this).css("display") == "none" });
                
                if(ul.length) {
                  return;
                }

                var currentRow = $(e.currentTarget).parents('tr');
                if (e.which == 38/*up*/) {
                    e.preventDefault();
                    var prevRow = currentRow.prev();
                    if (prevRow.length > 0) {
                        var currentObjectClass = $(e.currentTarget).prop('class');
                        currentObjectClass = '.' + currentObjectClass.replace(/ /g, ".");
                        prevRow.find(currentObjectClass).focus();

						/*check if current row is new empty row, remove it, condition: rawId && rawName empty*/
                        $currentProcessName = currentRow.find('input.process-name').val();
                        if ($currentProcessName == '') {
                            currentRow.remove();
                        }
                    }
                } else if (e.which == 40 /*down*/) {
                    var nextRow = currentRow.next();

                    if (nextRow.length > 0) {
                        var currentObjectClass = $(e.currentTarget).prop('class');
                        currentObjectClass = '.' + currentObjectClass.replace(/ /g, ".");
                        nextRow.find(currentObjectClass).focus();
                    } else {
                        $(e.currentTarget).parents('table').find('.btn-add-more').click();
                    }
                }
                // }
                // if(e.ctrlKey){
                if (e.which == 13) {
                    e.preventDefault();
                    $('#saveProcess').click();
                }
            });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment