This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
drupalcampbristol/web/modules/contrib/webform/js/webform.element.multiple.js
2018-11-23 12:29:20 +00:00

54 lines
1.5 KiB
JavaScript

/**
* @file
* JavaScript behaviors for multiple element.
*/
(function ($, Drupal) {
'use strict';
/**
* Move show weight to after the table.
*
* @type {Drupal~behavior}
*/
Drupal.behaviors.webformMultipleTableDrag = {
attach: function (context, settings) {
for (var base in settings.tableDrag) {
if (settings.tableDrag.hasOwnProperty(base)) {
$(context).find('.js-form-type-webform-multiple #' + base).once('webform-multiple-table-drag').each(function () {
var $tableDrag = $(this);
var $toggleWeight = $tableDrag.prev().prev('.tabledrag-toggle-weight-wrapper');
if ($toggleWeight.length) {
$toggleWeight.addClass('webform-multiple-tabledrag-toggle-weight');
$tableDrag.after($toggleWeight);
}
});
}
}
}
};
/**
* Submit multiple add number input value when enter is pressed.
*
* @type {Drupal~behavior}
*/
Drupal.behaviors.webformMultipleAdd = {
attach: function (context, settings) {
$(context).find('.js-webform-multiple-add').once('webform-multiple-add').each(function () {
var $submit = $(this).find('input[type="submit"], button');
var $number = $(this).find('input[type="number"]');
$number.keyup(function (event) {
if (event.which === 13) {
// Note: Mousedown is the default trigger for Ajax events.
// @see Drupal.Ajax.
$submit.mousedown();
}
});
});
}
};
})(jQuery, Drupal);