<commit_before>#= require './generic_page'

class Fustrate.GenericForm extends Fustrate.GenericPage
  addEventListeners: =>
    super

    @root.on 'submit', @onSubmit

  _reloadUIElements: =>
    super

    for domObject in $('[name][id]', @root)
      element = $ domObject
      name = element.prop 'name'

      if captures = name.match /\[([a-z_]+)\]$/
        @fields[captures[1]] = element
      else
        @fields[name] = element

  validate: -> true

  onSubmit: (e) =>
    e.preventDefault()

    unless @validate()
      setTimeout (=> $.rails.enableFormElements(@root)), 100

      return false

    true<commit_msg>don't prevent default if validation succeeds<commit_after>#= require './generic_page'

class Fustrate.GenericForm extends Fustrate.GenericPage
  addEventListeners: =>
    super

    @root.on 'submit', @onSubmit

  _reloadUIElements: =>
    super

    for domObject in $('[name][id]', @root)
      element = $ domObject
      name = element.prop 'name'

      if captures = name.match /\[([a-z_]+)\]$/
        @fields[captures[1]] = element
      else
        @fields[name] = element

  validate: -> true

  onSubmit: (e) =>
    return true if @validate()

    e.preventDefault()

    setTimeout (=> $.rails.enableFormElements(@root)), 100

    false
{'fraction_non_alphanumeric': 0.1415168100078186, 'fraction_numerical': 0.006254886630179828, 'mean_word_length': 2.78698224852071, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2010005', 'n_tokens_mistral': 419, 'n_tokens_neox': 392, 'n_words': 96}