<commit_before>###################################################################
# a property can be attached to a field.  Properties are used
# to implement validity checking for fields

#TODO implment caching of property-values
class Property
  # override evaluate to return the result of the property
  def self.evaluate(form,field,value)
    false
  end
  def self.render(question_html,property_value,question,form,read_only)
    question_html + property_value.to_s
  end
end

class Invalid < Property
  def self.evaluate(form,field,value)
    form.validating? ? Constraints.verify(field.constraints, value, form) : []
  end
  def self.render(question_html,property_value,question,form,read_only)
    if !property_value.empty? && (v = form.validating?) && !read_only
      errs = property_value.join("; ")
      if v != :no_explanation
        error_class = "validation_item"
        fname = question.field.name
        ex_val = form.get_record.explanation(fname)
#        if read_only
#          errs += ex_val.blank? ? ";(no explanation given)" : "; (explained with: #{ex_val})"
#        else
          errs += "; please correct (or explain here: <input id=\"explanations_#{fname}\" name=\"explanations[#{fname}]\" type=\"text\" value=\"#{ex_val}\" />)"
#        end
      else
        error_class = "validation_error"
      end
      question_html + %Q| <div class="#{error_class}">#{errs}</div>|
    else
      question_html
    end
  end
end<commit_msg>Now can tab to first error<commit_after>###################################################################
# a property can be attached to a field.  Properties are used
# to implement validity checking for fields

#TODO implment caching of property-values
class Property
  # override evaluate to return the result of the property
  def self.evaluate(form,field,value)
    false
  end
  def self.render(question_html,property_value,question,form,read_only)
    question_html + property_value.to_s
  end
end

class Invalid < Property
  def self.evaluate(form,field,value)
    form.validating? ? Constraints.verify(field.constraints, value, form) : []
  end
  def self.render(question_html,property_value,question,form,read_only)
    if !property_value.empty? && (v = form.validating?) && !read_only
      errs = property_value.join("; ")
      if v != :no_explanation
        error_class = "validation_item"
        fname = question.field.name
        ex_val = form.get_record.explanation(fname)
#        if read_only
#          errs += ex_val.blank? ? ";(no explanation given)" : "; (explained with: #{ex_val})"
#        else
          errs += "; please correct (or explain here: <input id=\"explanations_#{fname}\" name=\"explanations[#{fname}]\" type=\"text\" value=\"#{ex_val}\" />)"
#        end
      else
        error_class = "validation_error"
      end
      question_html + %Q| <div tabindex="1" class="#{error_class}">#{errs}</div>|
    else
      question_html
    end
  end
end
{'fraction_non_alphanumeric': 0.16079891672308733, 'fraction_numerical': 0.00033852403520649965, 'mean_word_length': 3.595645412130638, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '7523785', 'n_tokens_mistral': 893, 'n_tokens_neox': 886, 'n_words': 221}