Class: AlText

Inherits:
AlWidget show all
Defined in:
lib/al_form.rb

Overview

テキストウィジェット

Direct Known Subclasses

AlHidden, AlMail, AlPassword, AlTextArea

Instance Attribute Summary collapse

Attributes inherited from AlWidget

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

Instance Method Summary collapse

Methods inherited from AlWidget

#make_tag, #make_value, #set_attr

Constructor Details

#initialize(name, arg = {}) ⇒ AlText

(AlText) constructor

Parameters:

  • name (String)

    ウィジェット識別名 英文字を推奨

  • arg (Hash) (defaults to: {})

    引数ハッシュ

Options Hash (arg):

  • :validator (Regexp)

    バリデータ正規表現

  • :max (Integer)

    最大長さ

  • :min (Integer)

    最小長さ

See Also:



755
756
757
758
759
760
# File 'lib/al_form.rb', line 755

def initialize( name, arg = {} )
  super( name, arg )
  @validator = arg[:validator] || /[^\x00-\x1F\x7F]/
  @max = arg[:max]
  @min = arg[:min]
end

Instance Attribute Details

#maxInteger

Returns 最大長さ.

Returns:

  • (Integer)

    最大長さ



739
740
741
# File 'lib/al_form.rb', line 739

def max
  @max
end

#minInteger

Returns 最小長さ.

Returns:

  • (Integer)

    最小長さ



742
743
744
# File 'lib/al_form.rb', line 742

def min
  @min
end

#validatorRegexp

Returns 正規表現によるバリデータ。正常パターンを登録する。.

Returns:

  • (Regexp)

    正規表現によるバリデータ。正常パターンを登録する。



736
737
738
# File 'lib/al_form.rb', line 736

def validator
  @validator
end

Instance Method Details

#set_value(v) ⇒ Object Also known as: value=

(AlText) 値のセット

Parameters:

  • v (String)

    セットする値



768
769
770
# File 'lib/al_form.rb', line 768

def set_value( v )
  @value = v.to_s
end

#validateBoolean

(AlText) バリデート

Returns:

  • (Boolean)

    成否



779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
# File 'lib/al_form.rb', line 779

def validate()
  @message = ""

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

  if @max && @value.length > @max
    @message = "#{@label}は、最大#{@max}文字で入力してください。"
    return false
  end
  if @min && @value.length < @min
    @message = "#{@label}は、最低#{@min}文字入力してください。"
    return false
  end

  if @validator !~ @value
    @message = "#{@label}を正しく入力してください。"
    return false
  end

  return true
end