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, #value_format

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:



760
761
762
763
764
765
# File 'lib/al_form.rb', line 760

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)

    最大長さ



744
745
746
# File 'lib/al_form.rb', line 744

def max
  @max
end

#minInteger

Returns 最小長さ.

Returns:

  • (Integer)

    最小長さ



747
748
749
# File 'lib/al_form.rb', line 747

def min
  @min
end

#validatorRegexp

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

Returns:

  • (Regexp)

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



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

def validator
  @validator
end

Instance Method Details

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

(AlText) 値のセット

Parameters:

  • v (String)

    セットする値



773
774
775
# File 'lib/al_form.rb', line 773

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

#validateBoolean

(AlText) バリデート

Returns:

  • (Boolean)

    成否



784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
# File 'lib/al_form.rb', line 784

def validate()
  @message = ""

  if @value == "" || @value == nil
    if @required
      @message = p_("al", "%s is required.") % @label
      return false
    end
    return true
  end

  if @max && @value.length > @max
    @message = p_("al", "%1$s must be entered within %2$d characters.") % [@label, @max]
    return false
  end
  if @min && @value.length < @min
    @message = p_("al", "%1$s must be at least %2$d characters long.") % [@label, @min]
    return false
  end

  if @validator !~ @value
    @message = p_("al", "Please enter %s correctly.") % @label
    return false
  end

  return true
end