Form API Keybinds

Categories

Component ID

2577115

Component name

Form API Keybinds

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

527

Component created

Component changed

Component body

Introduction

Form Keybinds allows module developers to bind keypress events to form API
elements in custom forms.

Requirements

This module requires the following modules:

This module also requires the following third party libraries:

Installation

  1. Install as you would normally install a contributed Drupal module. See:
    https://drupal.org/documentation/install/modules-themes/modules-7
    for further information.
  2. Download the Mousetrap JavaScript library and place the mousetrap.js file
    in sites/all/libraries/mousetrap.

Configuration

To utilize keybinds on your button or submit elements, you just supply a #key_binds key in your element's definition array. The value of this key is an array of keyboard keys that can be pressed to trigger the element's click/submit action. Please refer to the Mousetrap documentation for allowed values: https://craig.is/killing/mice.

Example:

$form['submit'] = array(
  '#type' => 'submit',
  '#value' => t('Save'),
  '#key_binds' => array('shift+1', 'ctrl+1'),
);