From drupal core ajax.js:

<?php
Drupal
.ajax.prototype.keypressResponse = function (element, event) {
 
// Create a synonym for this to reduce code confusion.
 
var ajax = this;

 

// Detect enter key and space bar and allow the standard response for them,
  // except for form elements of type 'text' and 'textarea', where the
  // spacebar activation causes inappropriate activation if #ajax['keypress'] is
  // TRUE. On a text-type widget a space should always be a space.
 
if (event.which == 13 || (event.which == 32 && element.type != 'text' && element.type != 'textarea')) {
    $(
ajax.element_settings.element).trigger(ajax.element_settings.event);
    return
false;
  }
};
?>

I propose changing line 98 of horizontal-tabs/horizontal-tabs.js to:

<?php
if (event.keyCode == 13 && event.target.type != "textarea" && event.target.type != "text") {
?>

Comments

arosboro’s picture

Issue summary:View changes

Updated issue summary.

zuuperman’s picture

Issue summary:View changes
Status:Active» Closed (works as designed)

This works the same like drupal core js. See line 87 of misc/vertical-tabs.js

Alyssa Gono’s picture

Im sorry Im a beginner, and I dont get it.

Im trying to detect ENTER keypress event in my textfield but it doesnt work. What file should I edit? Below is my code:

    function id_print_user_page_form()
   {
        $form = array();
        $form['idnumber'] = array(
            '#type' => 'textfield',          
            '#ajax' => array( 
                'keypress' => TRUE
                'event' => 'keypress',       
                'callback' => 'id_print_search_idnumber',         
                'wrapper' => 'id_print_search_idnumber_wrapper',
            ),
        );

        $form['id_print_search_idnumber_wrapper'] = array(
            '#type' => 'item',     
            '#markup' => '<div id= "id_print_search_idnumber_wrapper"></div>',                       
        );

        return $form;
    }

     function id_print_search_idnumber(&$form, &$form_state)
    {
        return 'Its working';
    }