<commit_before>/**
 * @ngdoc directive
 * @name ngForm
 *
 * @description
 * Description place holder.
 **/
(function () {
  'use strict';

  function aaFormFactory(isNgForm, aaFormExtensions, aaNotify, $parse, $injector, $timeout, $q, aaLoadingWatcher, aaUtils) {
    return {
      restrict: isNgForm ? 'EAC' : 'E',
      require: 'form',
      compile: function () {
        return {
          pre: function (scope, element, attrs, thisForm) {

            function setAttemptRecursively(form, isInvalid) {
              form.$aaFormExtensions.$invalidAttempt = isInvalid;

              angular.forEach(form.$aaFormExtensions.$childForms, function (childForm) {
                setAttemptRecursively(childForm, isInvalid);
              });
            }

            //have to manually find parent forms '?^form' doesn't appear to work in this case (as it is very funky)
            var parentForm = element.parent().controller('form');

            thisForm.$aaFormExtensions = {
              $onSubmitAttempt: function () {
                setAttemptRecursively(thisForm, thisForm.$invalid);
              },
              $parentForm: parentForm,
              $childForms: [],
              $allValidationErrors: [],
              $changeDependencies: [],
              $changed: false,
              $invalidAttempt: false,
              $addChangeDependency: $addChangeDependency,

              //reset all changes back to their original values per $changeDependencies
              $reset: $reset,

              //reset $changeDependencies. All the current values are now the new inital values
              $resetChanged: $resetChanged,

              //clear form errors
              $clearErrors: $clearErrors,

              $addValidationError: $addValidationError

              // $multiFieldValidationErrors: [] //todo: add this back if multiple messages repeated is bad
            };

            if (parentForm) {
              parentForm.$aaFormExtensions.$childForms.push(thisForm);
            }

            //only root forms get the opportunity to block router state changes
            //add option to disable confirmation messages e.g. after form submit user redirection
            if (!parentForm && attrs.aaConfirmationMessage !== "false") {
              var strategy = aaFormExtensions.onNavigateAwayStrategies[attrs.onNavigateAwayStrategy || aaFormExtensions.defaultOnNavigateAwayStrategy ];
              if (angular.isFunction(strategy)) {
                strategy(scope, thisForm, $injector);
              }
            }

            //pick up any todos off the queue for this form
            scope.$watchCollection(function () {
                return scope.$$aaFormExtensionsTodos;
              },
              function (val) {

                if (!val) {
                  return;
                }

                for (var i = scope.$$aaFormExtensionsTodos.length - 1; i >= 0; i--) {
                  var todo = scope.$$aaFormExtensionsTodos[i];

                  if (todo.targetFormName === thisForm.$name || (!todo.targetFormName && !thisForm.$aaFormExtensions.$parentForm)) {

                    thisForm.$aaFormExtensions[todo.type].apply(this, todo.args);   //call the func
                    scope.$$aaFormExtensionsTodos.splice(i, 1);                     //remove from queue
                  }
                }
              });

            scope.$on('$destroy', function () {

              //when this form's scope is disposed clean up any references THIS form on parent forms
              //to prevent memory leaks in the case of a ng-if switching out child forms etc.
              var ngModelsToRemove = [];
              if (thisForm.$aaFormExtensions.$parentForm) {
                //collected native form fields (for $allValidationErrors)
                angular.forEach(thisForm, function (fieldVal, fieldName) {
                  if (fieldName.indexOf('$') !== 0) {
                    ngModelsToRemove.push(fieldVal);
                  }
                });

                //remove from parent forms recursively
                recurseForms(thisForm.$aaFormExtensions.$parentForm);
              }

              function recurseForms(form) {

                if (!form.$aaFormExtensions.$allValidationErrors.length) {
                  return;
                }

                //REMOVE this forms fields from $allValidationErrors
                angular.forEach(ngModelsToRemove, function (fieldToRemove) {

                  var valErrorField;

                  for (var i = form.$aaFormExtensions.$allValidationErrors.length; i >= 0, i--;) {
                    valErrorField = form.$aaFormExtensions.$allValidationErrors[i];
                    if (valErrorField.field.$ngModel === fieldToRemove) {
                      form.$aaFormExtensions.$allValidationErrors.splice(i, 1);
                    }
                  }
                });

                //REMOVE this forms reference as being a child form
                aaUtils.arrayRemove(form.$aaFormExtensions.$childForms, thisForm);

                //REMOVE this forms changed dependencies
                angular.forEach(thisForm.$aaFormExtensions.$changeDependencies, function (dep) {
                  aaUtils.arrayRemove(form.$aaFormExtensions.$changeDependencies, dep);
                  aaUtils.checkAndSetFormChanged(form);<commit_msg>fixed issue when validation errors were added w/o a field<commit_after>/**
 * @ngdoc directive
 * @name ngForm
 *
 * @description
 * Description place holder.
 **/
(function () {
  'use strict';

  function aaFormFactory(isNgForm, aaFormExtensions, aaNotify, $parse, $injector, $timeout, $q, aaLoadingWatcher, aaUtils) {
    return {
      restrict: isNgForm ? 'EAC' : 'E',
      require: 'form',
      compile: function () {
        return {
          pre: function (scope, element, attrs, thisForm) {

            function setAttemptRecursively(form, isInvalid) {
              form.$aaFormExtensions.$invalidAttempt = isInvalid;

              angular.forEach(form.$aaFormExtensions.$childForms, function (childForm) {
                setAttemptRecursively(childForm, isInvalid);
              });
            }

            //have to manually find parent forms '?^form' doesn't appear to work in this case (as it is very funky)
            var parentForm = element.parent().controller('form');

            thisForm.$aaFormExtensions = {
              $onSubmitAttempt: function () {
                setAttemptRecursively(thisForm, thisForm.$invalid);
              },
              $parentForm: parentForm,
              $childForms: [],
              $allValidationErrors: [],
              $changeDependencies: [],
              $changed: false,
              $invalidAttempt: false,
              $addChangeDependency: $addChangeDependency,

              //reset all changes back to their original values per $changeDependencies
              $reset: $reset,

              //reset $changeDependencies. All the current values are now the new inital values
              $resetChanged: $resetChanged,

              //clear form errors
              $clearErrors: $clearErrors,

              $addValidationError: $addValidationError

              // $multiFieldValidationErrors: [] //todo: add this back if multiple messages repeated is bad
            };

            if (parentForm) {
              parentForm.$aaFormExtensions.$childForms.push(thisForm);
            }

            //only root forms get the opportunity to block router state changes
            //add option to disable confirmation messages e.g. after form submit user redirection
            if (!parentForm && attrs.aaConfirmationMessage !== "false") {
              var strategy = aaFormExtensions.onNavigateAwayStrategies[attrs.onNavigateAwayStrategy || aaFormExtensions.defaultOnNavigateAwayStrategy ];
              if (angular.isFunction(strategy)) {
                strategy(scope, thisForm, $injector);
              }
            }

            //pick up any todos off the queue for this form
            scope.$watchCollection(function () {
                return scope.$$aaFormExtensionsTodos;
              },
              function (val) {

                if (!val) {
                  return;
                }

                for (var i = scope.$$aaFormExtensionsTodos.length - 1; i >= 0; i--) {
                  var todo = scope.$$aaFormExtensionsTodos[i];

                  if (todo.targetFormName === thisForm.$name || (!todo.targetFormName && !thisForm.$aaFormExtensions.$parentForm)) {

                    thisForm.$aaFormExtensions[todo.type].apply(this, todo.args);   //call the func
                    scope.$$aaFormExtensionsTodos.splice(i, 1);                     //remove from queue
                  }
                }
              });

            scope.$on('$destroy', function () {

              //when this form's scope is disposed clean up any references THIS form on parent forms
              //to prevent memory leaks in the case of a ng-if switching out child forms etc.
              var ngModelsToRemove = [];
              if (thisForm.$aaFormExtensions.$parentForm) {
                //collected native form fields (for $allValidationErrors)
                angular.forEach(thisForm, function (fieldVal, fieldName) {
                  if (fieldName.indexOf('$') !== 0) {
                    ngModelsToRemove.push(fieldVal);
                  }
                });

                //remove from parent forms recursively
                recurseForms(thisForm.$aaFormExtensions.$parentForm);
              }

              function recurseForms(form) {

                if (!form.$aaFormExtensions.$allValidationErrors.length) {
                  return;
                }

                //REMOVE this forms fields from $allValidationErrors
                angular.forEach(ngModelsToRemove, function (fieldToRemove) {

                  var valErrorField;

                  for (var i = form.$aaFormExtensions.$allValidationErrors.length; i >= 0, i--;) {
                    valErrorField = form.$aaFormExtensions.$allValidationErrors[i];
                    if (!valErrorField.field || valErrorField.field.$ngModel === fieldToRemove) {
                      form.$aaFormExtensions.$allValidationErrors.splice(i, 1);
                    }
                  }
                });

                //REMOVE this forms reference as being a child form
                aaUtils.arrayRemove(form.$aaFormExtensions.$childForms, thisForm);

                //REMOVE this forms changed dependencies
                angular.forEach(thisForm.$aaFormExtensions.$changeDependencies, function (dep) {
                  aaUtils.arrayRemove(form.$aaFormExtensions.$changeDependencies, dep);
                  aaUtils.checkAndSetFormChanged(form);
{'fraction_non_alphanumeric': 0.09574272023590122, 'fraction_numerical': 0.0011057869517139699, 'mean_word_length': 1.7420414350682163, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7645876', 'n_tokens_mistral': 2696, 'n_tokens_neox': 2497, 'n_words': 651}