<commit_before>(function () {
  'use strict';

  /**
   * @ngdoc directive
   * @name components.ui.msmFormSubmit
   * @scope
   * @restrict 'A'
   *
   * @description Directive for setting a 'loading' true/false flag on a form controller. You need to make sure that
   * your submit function returns a promise for this to work. Use this as a replacement for angular's 'ngSubmit' directive.
   *
   * @example <form msm-form-submit="submitMyFormMethod">...</form>
   */
  angular
      .module('msm.components.ui')
      .directive('msmFormSubmit', MsmFormSubmit);

  function MsmFormSubmit() {
    return {
      restrict: 'A',
      require: '^form',
      transclude: true,
      template: '<fieldset ng-disabled="_form.loading"><ng-transclude></ng-transclude></fieldset>',
      scope: {
        msmFormSubmit: '&'
      },
      link: function (scope, element, attrs, formCtrl) {
        scope._form = formCtrl;

        element.on('submit', function () {
          formCtrl.loading = true;
          scope.$apply();

          scope.msmFormSubmit().finally(function () {
            formCtrl.loading = false;
          });
        });
      }
    };
  }
})();<commit_msg>Correctly handle missing promise in msmFormSubmit<commit_after>(function () {
  'use strict';

  /**
   * @ngdoc directive
   * @name components.ui.msmFormSubmit
   * @scope
   * @restrict 'A'
   *
   * @description Directive for setting a 'loading' true/false flag on a form controller. You need to make sure that
   * your submit function returns a promise for this to work. Use this as a replacement for angular's 'ngSubmit' directive.
   *
   * @example <form msm-form-submit="submitMyFormMethod">...</form>
   */
  angular
      .module('msm.components.ui')
      .directive('msmFormSubmit', MsmFormSubmit);

  function MsmFormSubmit() {
    return {
      restrict: 'A',
      require: '^form',
      transclude: true,
      template: '<fieldset ng-disabled="_form.loading"><ng-transclude></ng-transclude></fieldset>',
      scope: {
        msmFormSubmit: '&'
      },
      link: function (scope, element, attrs, formCtrl) {
        scope._form = formCtrl;
        element.on('submit', function () {
          var submitPromise = scope.msmFormSubmit();
          if (submitPromise && angular.isFunction(submitPromise.finally)) {
            formCtrl.loading = true;
            submitPromise.finally(function () {
              formCtrl.loading = false;
            });
          }
        });
      }
    };
  }
})();
{'fraction_non_alphanumeric': 0.13543747502996403, 'fraction_numerical': 0.0, 'mean_word_length': 2.4490358126721765, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2277582', 'n_tokens_mistral': 727, 'n_tokens_neox': 734, 'n_words': 178}