Module: KajabiParsleyHelper
- Defined in:
- app/helpers/kajabi_parsley_helper.rb
Instance Method Summary collapse
- #length_validation_for_parsley(klass, field) ⇒ Object
- #parsley_max(klass, field) ⇒ Object
- #parsley_min(klass, field) ⇒ Object
- #parsley_minmax(klass, field) ⇒ Object
Instance Method Details
#length_validation_for_parsley(klass, field) ⇒ Object
33 34 35 36 37 38 |
# File 'app/helpers/kajabi_parsley_helper.rb', line 33 def length_validation_for_parsley(klass, field) klass = klass.is_a?(Class) ? klass : klass.class validators = klass.validators.select {|v| v.is_a?(ActiveModel::Validations::LengthValidator)} validators.detect { |v| v.attributes == [field.to_sym] } end |
#parsley_max(klass, field) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/kajabi_parsley_helper.rb', line 9 def parsley_max(klass, field) validator = length_validation_for_parsley(klass, field) max = validator.[:maximum] { parsley_trigger: 'keyup', parsley_maxlength: max, parsley_maxlength_message: t('errors.messages.too_long', count: max), } end |
#parsley_min(klass, field) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/helpers/kajabi_parsley_helper.rb', line 21 def parsley_min(klass, field) validator = length_validation_for_parsley(klass, field) min = validator.[:minimum] { parsley_trigger: 'keyup', parsley_minlength: min, parsley_minlength_message: t('errors.messages.too_short', count: min), } end |
#parsley_minmax(klass, field) ⇒ Object
2 3 4 5 6 7 |
# File 'app/helpers/kajabi_parsley_helper.rb', line 2 def parsley_minmax(klass, field) min = parsley_min(klass, field) max = parsley_max(klass, field) min.merge(max) end |