Class: AlInteger

Inherits:
AlNumber show all
Defined in:
lib/al_form.rb,
lib/al_form/extend.rb

Overview

整数入力ウィジェット

Instance Attribute Summary

Attributes inherited from AlNumber

#max, #min

Attributes inherited from AlWidget

#filter, #foreign, #hidden, #label, #message, #name, #required, #tag_attr, #value

Instance Method Summary (collapse)

Methods inherited from AlNumber

#initialize, #make_tag

Methods inherited from AlWidget

#initialize, #make_value, #set_attr, #set_value

Constructor Details

This class inherits a constructor from AlNumber

Instance Method Details

- (Boolean) validate

(AlInteger) バリデート

Returns:

  • (Boolean)

    成否



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/al_form/extend.rb', line 56

def validate()
  @message = ""

  if @value == "" || @value == nil
    if @required
      @message = "#{@label}を入力してください。"
      return false
    end
    @value = nil
    return true
  end

  if /^[\s]*[+-]?[\d]+[\s]*$/ !~ @value.to_s
    @message = "#{@label}は整数で入力してください。"
    return false
  end

  v = @value.to_i
  if @max && v > @max
    @message = "#{@label}は、#{@max}以下を入力してください。"
    return false
  end
  if @min && v < @min
    @message = "#{@label}は、#{@min}以上を入力してください。"
    return false
  end
  @value = v

  return true
end