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:
- Libraries API (https://drupal.org/project/libraries)
This module also requires the following third party libraries:
- Mousetrap (https://github.com/ccampbell/mousetrap)
Installation
- Install as you would normally install a contributed Drupal module. See:
https://drupal.org/documentation/install/modules-themes/modules-7
for further information. - 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'),
);
