Class: CustomFieldDatePair
- Inherits:
-
CustomFieldPair
- Object
- ActiveRecord::Base
- Field
- CustomField
- CustomFieldPair
- CustomFieldDatePair
- Defined in:
- app/models/fields/custom_field_date_pair.rb
Overview
Copyright © 2008-2013 Michael Dvorkin and contributors.
Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php
Direct Known Subclasses
Constant Summary
Constants inherited from CustomField
CustomField::SAFE_DB_TRANSITIONS
Constants inherited from Field
Instance Method Summary collapse
- #custom_validator(obj) ⇒ Object
- #render(value) ⇒ Object
-
#render_value(object) ⇒ Object
For rendering paired values Handle case where both pairs are blank ——————————————————————————.
Methods inherited from CustomFieldPair
create_pair, #paired_with, update_pair
Methods inherited from CustomField
Methods inherited from Field
#collection_string, #collection_string=, #column_type, field_types, #input_options, lookup_class, register
Instance Method Details
#custom_validator(obj) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/fields/custom_field_date_pair.rb', line 32 def custom_validator(obj) super # validate when we get to 2nd of the pair if pair_id.present? start = CustomFieldPair.find(pair_id) return if start.nil? from = obj.send(start.name) to = obj.send(name) obj.errors.add(name.to_sym, ::I18n.t('activerecord.errors.models.custom_field.endbeforestart', field: start.label)) if from.present? && to.present? && (from > to) end end |
#render(value) ⇒ Object
28 29 30 |
# File 'app/models/fields/custom_field_date_pair.rb', line 28 def render(value) value&.strftime(I18n.t("date.formats.mmddyy")) end |
#render_value(object) ⇒ Object
For rendering paired values Handle case where both pairs are blank
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/fields/custom_field_date_pair.rb', line 12 def render_value(object) return "" unless paired_with.present? from = render(object.send(name)) to = render(object.send(paired_with.name)) if from.present? && to.present? I18n.t('pair.from_to', from: from, to: to) elsif from.present? && !to.present? I18n.t('pair.from_only', from: from) elsif !from.present? && to.present? I18n.t('pair.to_only', to: to) else "" end end |