class Ezframe::IntType
Public Instance Methods
db_type()
click to toggle source
# File lib/ezframe/column_type.rb, line 228 def db_type return "int" end
form(opts = {})
click to toggle source
# File lib/ezframe/column_type.rb, line 210 def form(opts = {}) return nil if no_edit? && !opts[:force] key = self.key key ="#{key}#{opts[:key_suffix]}" if opts[:key_suffix] h = Ht.input(type: "number", name: key, label: @attribute[:label], value: @value || "") h[:class] = @attribute[:class] if @attribute[:class] h[:after] = make_error_box(key) return h end
normalize(val)
click to toggle source
# File lib/ezframe/column_type.rb, line 180 def normalize(val) if val.is_a?(String) val = val.tr("0-9", "0-9").strip end return val end
validate(val)
click to toggle source
# File lib/ezframe/column_type.rb, line 220 def validate(val) return nil if !val || val.to_s.strip.empty? unless /^\d+$/ =~ val.to_s return :invalid_value end return nil end
value=(v)
click to toggle source
# File lib/ezframe/column_type.rb, line 187 def value=(v) if v.nil? default = @attribute[:default] if default @value = default else @value = nil end return end if v.nil? @value = nil return end unless v.is_a?(Integer) || v.is_a?(String) EzLog.debug("value must integer or string: key=#{self.key}, #{v}: class=#{v.class}") return end v = normalize(v) @value = v.to_i end
view(opts = {})
click to toggle source
# File lib/ezframe/column_type.rb, line 165 def view(opts = {}) return nil if no_view? && !opts[:force] return nil unless @value return nil if @attribute[:no_view_if_zero] && @value.to_i == 0 if @attribute[:view_format] return use_view_format(@attribute[:view_format], @value) else if @attribute[:add_comma] return @value.to_i.add_comma else return @value.to_s end end end