<commit_before>angular.module('dynamicHandsontable', ['ngHandsontable'])

.directive('htDynamic', function($compile) {
  return {
    restrict: 'E',
    scope: {
      spec: '=',
      data: '='
    },
    templateUrl: 'dynamicHandsontable/template.html',
    link: function(scope, element) {
      var getType = function(typeInt) {
        switch(typeInt) {
          case 2:
            return 'text';
          case 1:
            return 'numeric';
        }
      };

      scope.$watch('spec', function() {
        if(scope.spec) {
          scope.columns = scope.spec.map(function(s) {
            return {
              // type: getType(s.TYPE),
              data: s.NAME.toUpperCase(),
              title: s.NAME
            };
          });

          scope.settings = {
            beforeChange: function (changes) {
              for(var i = 0; i < scope.spec.length; i++) {
                for(var j = 0; j < changes.length; j++) {
                  if(changes[j][1] === scope.spec[i].NAME.toUpperCase()) {
                    if(changes[j][3].length > scope.spec[i].LENGTH) {
                      alert('Max length exceeded');
                      changes.splice(j, 1);
                    } else if(getType(scope.spec[i].TYPE) === 'numeric') {
                      if(isNaN(changes[j][3])) {
                        alert('Only numeric values are accepted');
                        changes.splice(j, 1);
                      } else {
                        changes[j][3] = parseFloat(changes[j][3]);
                      }
                    }
                  }
                }
              }
            },
            afterChange: function(changes, source) {
              //TODO: save
              console.log(changes);
            }
          };
        }
      });
    }
  };
});<commit_msg>Changed validation and removed afterChange event listener<commit_after>angular.module('dynamicHandsontable', ['ngHandsontable'])

.directive('htDynamic', function($compile) {
  return {
    restrict: 'E',
    scope: {
      spec: '=',
      data: '='
    },
    templateUrl: 'dynamicHandsontable/template.html',
    link: function(scope, element) {
      var getType = function(typeInt) {
        switch(typeInt) {
          case 2:
            return 'text';
          case 1:
            return 'numeric';
        }
      };

      scope.$watch('spec', function() {
        if(scope.spec) {
          scope.columns = scope.spec.map(function(s) {
            return {
              // type: getType(s.TYPE),
              data: s.NAME.toUpperCase(),
              title: s.NAME
            };
          });

          scope.settings = {
            beforeChange: function (changes) {
              for(var i = 0; i < scope.spec.length; i++) {
                for(var j = 0; j < changes.length; j++) {
                  if(changes[j][1] === scope.spec[i].NAME.toUpperCase()) {
                    if(getType(scope.spec[i].TYPE) !== 'numeric') {
                      if(changes[j][3].length > scope.spec[i].LENGTH) {
                        alert('Max length exceeded');
                        changes.splice(j, 1);
                      }
                    } else {
                      if(isNaN(changes[j][3])) {
                        alert('Only numeric values are accepted');
                        changes.splice(j, 1);
                      } else {
                        changes[j][3] = parseFloat(changes[j][3]);
                      }
                    }
                  }
                }
              }
            }
          };
        }
      });
    }
  };
});
{'fraction_non_alphanumeric': 0.13989494055847387, 'fraction_numerical': 0.006082388719933647, 'mean_word_length': 1.1821471652593487, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1063905', 'n_tokens_mistral': 1010, 'n_tokens_neox': 961, 'n_words': 168}