Class: AlFloat

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

(AlFloat) バリデート

Returns:

  • (Boolean)

    成否



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/al_form/extend.rb', line 101

def validate()
  @message = ""

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

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

  v = @value.to_f
  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