Class: ProposalLengthValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Includes:
ActionView::Helpers::SanitizeHelper
Defined in:
decidim-proposals/app/validators/proposal_length_validator.rb

Overview

This validator takes care of ensuring the validated attributes are long enough and not too long. The difference to the Rails length validator is that this allows the minimum and maximum values to be lambdas allowing us to fetch the maximum length dynamically for each proposals component.

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



10
11
12
13
14
15
16
# File 'decidim-proposals/app/validators/proposal_length_validator.rb', line 10

def validate_each(record, attribute, value)
  return if value.blank?

  text_value = strip_tags(value)
  validate_min_length(record, attribute, text_value)
  validate_max_length(record, attribute, text_value)
end