When we introduced the new formUpdated behavior we forgot to remove the old one from the file (no idea what happened).

CommentFileSizeAuthor
core-js-form-updated-deadcode.patch1.04 KBnod_
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sqndr’s picture

Status: Needs review » Reviewed & tested by the community

form.js, L43-60

  /**
   * Sends a 'formUpdated' event each time a form element is modified.
   */
  Drupal.behaviors.formUpdated = {
    attach: function (context) {
      // These events are namespaced so that we can remove them later.
      var events = 'change.formUpdated click.formUpdated blur.formUpdated keyup.formUpdated';
      $(context)
        // Since context could be an input element itself, it's added back to
        // the jQuery object and filtered again.
        .find(':input').addBack().filter(':input')
        // To prevent duplicate events, the handlers are first removed and then
        // (re-)added.
        .off(events).on(events, function () {
          $(this).trigger('formUpdated');
        });
    }
  };

form.js, L143-191:

  /**
   * Triggers the 'formUpdated' event on form elements when they are modified.
   */
  Drupal.behaviors.formUpdated = {
    attach: function (context) {
      var $context = $(context);
      var contextIsForm = $context.is('form');
      var $forms = (contextIsForm ? $context : $context.find('form')).once('form-updated');


      if ($forms.length) {
        // Initialize form behaviors, use $.makeArray to be able to use native
        // forEach array method and have the callback parameters in the right order.
        $.makeArray($forms).forEach(function (form) {
          var events = 'change.formUpdated keypress.formUpdated';
          var eventHandler = debounce(function (event) { triggerFormUpdated(event.target); }, 300);
          var formFields = fieldsList(form).join(',');

          form.setAttribute('data-drupal-form-fields', formFields);
          $(form).on(events, eventHandler);
        });
      }
      // On ajax requests context is the form element.
      if (contextIsForm) {
        var formFields = fieldsList(context).join(',');
        // @todo replace with form.getAttribute() when #1979468 is in.
        var currentFields = $(context).attr('data-drupal-form-fields');
        // if there has been a change in the fields or their order, trigger
        // formUpdated.
        if (formFields !== currentFields) {
          triggerFormUpdated(context);
        }
      }

    },
    detach: function (context, settings, trigger) {
      var $context = $(context);
      var contextIsForm = $context.is('form');
      if (trigger === 'unload') {
        var $forms = (contextIsForm ? $context : $context.find('form')).removeOnce('form-updated');
        if ($forms.length) {
          $.makeArray($forms).forEach(function (form) {
            form.removeAttribute('data-drupal-form-fields');
            $(form).off('.formUpdated');
          });
        }
      }
    }
  };

The patch removes this duplicate behavior.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed ff99927 and pushed to 8.x. Thanks!

  • alexpott committed ff99927 on 8.x
    Issue #2298665 by nod_: Fixed Remove dead code in form.js.
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.