Class: AlSelector

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

Overview

Note:

チェックボックス、プルダウンメニュー、ラジオボタン

セレクタウィジェット スーパークラス

Direct Known Subclasses

AlCheckboxes, AlOptions, AlRadios

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from AlWidget

#set_attr

Constructor Details

- (AlSelector) initialize(name, arg = {})

(AlSelector) constractor

Parameters:

  • (String) name

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

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

    引数ハッシュ

Options Hash (arg):

  • (Hash) :options N/A

    選択オプションのハッシュ

  • (String) :separator N/A

    HTMLタグを生成する場合のタグ間セパレータ

See Also:



892
893
894
895
896
897
# File 'lib/al_form.rb', line 892

def initialize( name, arg = {} )
  super( name, arg )
  @options = arg[:options]
  @separator = arg[:separator]
  raise "Need ':options' parameter when make widget."  if ! @options
end

Instance Attribute Details

- (Hash) options (readonly)

選択項目のハッシュ

Returns:

  • (Hash)

    選択項目のハッシュ



877
878
879
# File 'lib/al_form.rb', line 877

def options
  @options
end

- (String) separator (readonly)

HTMLタグを生成する場合のタグ間セパレータ

Returns:

  • (String)

    HTMLタグを生成する場合のタグ間セパレータ



880
881
882
# File 'lib/al_form.rb', line 880

def separator
  @separator
end

Instance Method Details

- (String) make_tag(arg = {})

Note:

フラグ @hidden の時のみ対応。その他はサブクラスへ委譲。

(AlSelector) HTMLタグの生成

Parameters:

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

    htmlタグへ追加するアトリビュートを指定

Returns:

  • (String)

    htmlタグ



944
945
946
947
948
949
950
951
952
# File 'lib/al_form.rb', line 944

def make_tag( arg = {} )
  @options.each do |k,v|
    if @value && @value.to_sym == k.to_sym
      return %Q(<input type="hidden" name="#{@name}" id="#{@name}" value="#{Alone::escape_html(k)}" #{AL_FORM_EMPTYTAG_CLOSE}\n)
    end
  end

  return ""
end

- (String) make_value(*arg)

(AlSelector) HTML値の生成

Parameters:

  • (String) arg

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

Returns:

  • (String)

    html文字列



961
962
963
964
965
966
967
# File 'lib/al_form.rb', line 961

def make_value( *arg )
  v = arg.empty? ? @value: arg[0]
  if v == "" || v == nil
    return ""
  end
  return Alone::escape_html( @options[v] || @options[v.to_sym] || @options[v.to_s] || @options[v.to_i] )
end

- (Object) set_value(v) Also known as: value=

(AlSelector) 値のセット

Parameters:

  • value

    セットする値



905
906
907
# File 'lib/al_form.rb', line 905

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

- (Boolean) validate

(AlSelector) バリデート

Returns:

  • (Boolean)

    成否



916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
# File 'lib/al_form.rb', line 916

def validate()
  @message = ""

  if @value == "" || @value == nil
    if @required
      @message = "#{@label}を選んでください。";
      return false
    end
    return true
  end

  if ! @options[@value.to_sym] && ! @options[@value.to_s] && ! @options[@value.to_i]
    @message = "#{@label}の入力が、規定値以外です。";
    return false
  end

  return true
end