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

  angular
    .module('app')
    .factory('FormFactory', FormFactory);

  FormFactory.$inject = ['$document', '$ionicPopup', '$log', '$rootScope', 'DataModelsFactory'];

  function FormFactory($document, $ionicPopup, $log, $rootScope, DataModelsFactory) {

    var form = {};   // form = {'choices': {}, 'survey': {}};

    return {
      'clearForm': clearForm,
      'clearFormElements': clearFormElements,
      'getForm': getForm,
      'getMax': getMax,
      'getMin': getMin,
      'isRelevant': isRelevant,
      'setForm': setForm,
      'toggleAcknowledgeChecked': toggleAcknowledgeChecked,
      'validate': validate,
      'validateForm': validateForm
    };

    /**
     * Public Functions
     */

    function clearForm() {
      form = {};
    }

    function clearFormElements() {
      var formCtrl = angular.element(document.getElementById('straboFormCtrlId')).scope();
      _.each(form.survey, function (field) {
        if (field.name) {
          var ele = document.getElementsByName(field.name)[0];
          var formEle = formCtrl.straboForm[ele.name];
          if (formEle && formEle.$valid === false) {
            ele.value = "";
            // formEle.$valid = true;  // These cause an error "Cannot create property 'min' on boolean 'false'"
            // formEle.$error = false; // when typing in a number
          }
        }
      });
    }

    function getForm() {
      return form;
    }

    // Get the max value allowed for a number field
    function getMax(constraint) {
      try {
        // Look for <= (= is optional) in constraint, followed by a space and then any number of digits (- preceding the digits is optional)
        var regexMax = /<=?\s(-?\d*)/i;
        // Return just the number
        return regexMax.exec(constraint)[1];
      }
      catch (e) {
        return undefined;
      }
    }<commit_msg>clear form bug fix<commit_after>(function () {
  'use strict';

  angular
    .module('app')
    .factory('FormFactory', FormFactory);

  FormFactory.$inject = ['$document', '$ionicPopup', '$log', '$rootScope', 'DataModelsFactory'];

  function FormFactory($document, $ionicPopup, $log, $rootScope, DataModelsFactory) {

    var form = {};   // form = {'choices': {}, 'survey': {}};

    return {
      'clearForm': clearForm,
      'clearFormElements': clearFormElements,
      'getForm': getForm,
      'getMax': getMax,
      'getMin': getMin,
      'isRelevant': isRelevant,
      'setForm': setForm,
      'toggleAcknowledgeChecked': toggleAcknowledgeChecked,
      'validate': validate,
      'validateForm': validateForm
    };

    /**
     * Public Functions
     */

    function clearForm() {
      form = {};
    }

    function clearFormElements() {
      var formCtrl = angular.element(document.getElementById('straboFormCtrlId')).scope();
      _.each(form.survey, function (field) {
        if (field.name) {
          var ele = document.getElementsByName(field.name)[0];
          if (ele) {
            var formEle = formCtrl.straboForm[ele.name];
            if (formEle && formEle.$valid === false) {
              ele.value = "";
              // formEle.$valid = true;  // These cause an error "Cannot create property 'min' on boolean 'false'"
              // formEle.$error = false; // when typing in a number
            }
          }
        }
      });
    }

    function getForm() {
      return form;
    }

    // Get the max value allowed for a number field
    function getMax(constraint) {
      try {
        // Look for <= (= is optional) in constraint, followed by a space and then any number of digits (- preceding the digits is optional)
        var regexMax = /<=?\s(-?\d*)/i;
        // Return just the number
        return regexMax.exec(constraint)[1];
      }
      catch (e) {
        return undefined;
      }
    }
{'fraction_non_alphanumeric': 0.1399793388429752, 'fraction_numerical': 0.0010330578512396695, 'mean_word_length': 2.26010101010101, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '4984521', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1092, 'n_words': 289}