Class: AlDate

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

Overview

Note:

年月日を扱う 内部的には時刻を0時に固定したTimeオブジェクトで保存する。

日付ウィジェット

Instance Method Summary (collapse)

Methods inherited from AlTimestamp

#initialize, #make_tag

Methods inherited from AlWidget

#initialize, #set_attr, #set_value

Constructor Details

This class inherits a constructor from AlTimestamp

Instance Method Details

- (String) make_value(*arg)

(AlDate) HTML値の生成

Parameters:

  • (String, Time) arg

    表示値。指定なければ内部値を使う。

Returns:

  • (String)

    html文字列



291
292
293
294
295
296
297
298
# File 'lib/al_form/extend.rb', line 291

def make_value( *arg )
  v = arg.empty? ? @value: arg[0]
  if v.class == Time
    return v.strftime('%Y-%m-%d')
  else
    return Alone::escape_html( v )
  end
end

- (Boolean) validate

(AlDate) バリデート

Returns:

  • (Boolean)

    成否



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/al_form/extend.rb', line 253

def validate()
  require 'time'
  @message = ""

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

  begin
    @value = Time.parse( @value + ' 00:00:00' )
  rescue
    @message = "#{@label}を正しく入力してください。"
    return false
  end

  if @max && @value > @max
    @message = "#{@label}は、最大#{@max.strftime('%Y-%m-%d')}までで入力してください。"
    return false
  end
  if @min && @value < @min
    @message = "#{@label}は、最小#{@min.strftime('%Y-%m-%d')}までで入力してください。"
    return false
  end

  return true
end