app/models/fields/field.rb in fat_free_crm-0.16.4 vs app/models/fields/field.rb in fat_free_crm-0.17.1

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + # Copyright (c) 2008-2013 Michael Dvorkin and contributors. # # Fat Free CRM is freely distributable under the terms of MIT license. # See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ @@ -19,10 +21,11 @@ # as :string(32) # collection :text # disabled :boolean # required :boolean # maxlength :integer +# minlength :integer # created_at :datetime # updated_at :datetime # class Field < ActiveRecord::Base @@ -56,22 +59,24 @@ 'float' => { klass: 'CustomField', type: 'float' } }.with_indifferent_access validates_presence_of :label, message: "^Please enter a field label." validates_length_of :label, maximum: 64, message: "^The field name must be less than 64 characters in length." - validates_numericality_of :maxlength, only_integer: true, allow_blank: true, message: "^Max size can only be whole number." + validates_numericality_of :minlength, only_integer: true, greater_than_or_equal_to: 0, allow_blank: true, message: "^Min size can only be whole number." + validates_numericality_of :minlength, less_than_or_equal_to: :maxlength, allow_blank: true, if: :maxlength, message: "^Min size cannot be greater than max size." + validates_numericality_of :maxlength, only_integer: true, greater_than: 0, allow_blank: true, message: "^Max size can only be whole number." validates_presence_of :as, message: "^Please specify a field type." validates_inclusion_of :as, in: proc { field_types.keys }, message: "^Invalid field type.", allow_blank: true def column_type(field_type = as) (opts = Field.field_types[field_type]) ? opts[:type] : raise("Unknown field_type: #{field_type}") end def input_options input_html = {} attributes.reject do |k, v| - !%w[as collection disabled label placeholder required maxlength].include?(k) || v.blank? + !%w[as collection disabled label placeholder required minlength maxlength].include?(k) || v.blank? end.symbolize_keys.merge(input_html) end def collection_string=(value) self.collection = value.split("|").map(&:strip).reject(&:blank?) @@ -88,12 +93,12 @@ def render(value) case as when 'checkbox' value.to_s == '0' ? "no" : "yes" when 'date' - value && value.strftime(I18n.t("date.formats.mmddyy")) + value&.strftime(I18n.t("date.formats.mmddyy")) when 'datetime' - value && value.in_time_zone.strftime(I18n.t("time.formats.mmddyyyy_hhmm")) + value&.in_time_zone&.strftime(I18n.t("time.formats.mmddyyyy_hhmm")) when 'check_boxes' value.select(&:present?).in_groups_of(2, false).map { |g| g.join(', ') }.join("<br />".html_safe) if Array === value else value.to_s end