Class: AlSelector
Overview
セレクタウィジェット スーパークラス
(チェックボックス、プルダウンメニュー、ラジオボタン)
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
- Hash
-
選択項目のハッシュ.
-
#separator ⇒ Object
readonly
- String
-
HTMLタグを生成する場合のタグ間セパレータ.
Attributes inherited from AlWidget
#filter, #foreign, #hidden, #label, #message, #name, #required, #tag_attr, #tag_type, #value
Instance Method Summary collapse
-
#initialize(name, arg = {}) ⇒ AlSelector
constructor
(AlSelector) constructor.
-
#make_tag(appendix_tag = {}) ⇒ String
(AlSelector) HTMLタグの生成.
-
#make_value(*arg) ⇒ String
(AlSelector) HTML値の生成.
-
#set_value(v) ⇒ Object
(also: #value=)
(AlSelector) 値のセット.
-
#validate ⇒ Boolean
(AlSelector) バリデート.
Methods inherited from AlWidget
Constructor Details
#initialize(name, arg = {}) ⇒ AlSelector
(AlSelector) constructor
941 942 943 944 945 946 |
# File 'lib/al_form.rb', line 941 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
#options ⇒ Object (readonly)
- Hash
-
選択項目のハッシュ
927 928 929 |
# File 'lib/al_form.rb', line 927 def @options end |
#separator ⇒ Object (readonly)
- String
-
HTMLタグを生成する場合のタグ間セパレータ
930 931 932 |
# File 'lib/al_form.rb', line 930 def separator @separator end |
Instance Method Details
#make_tag(appendix_tag = {}) ⇒ String
Note:
フラグ @hidden の時のみ対応。その他はサブクラスへ委譲。appendix_tagは使わない
(AlSelector) HTMLタグの生成
993 994 995 996 997 998 999 1000 1001 |
# File 'lib/al_form.rb', line 993 def make_tag( appendix_tag = {} ) @options.each do |k,v| if @value && @value.to_s == k.to_s return %Q(<input type="hidden" name="#{@name}" id="#{@name}" value="#{Alone::escape_html(k)}">\n) end end return "" end |
#make_value(*arg) ⇒ String
(AlSelector) HTML値の生成
1010 1011 1012 1013 1014 1015 1016 |
# File 'lib/al_form.rb', line 1010 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 |
#set_value(v) ⇒ Object Also known as: value=
(AlSelector) 値のセット
954 955 956 957 |
# File 'lib/al_form.rb', line 954 def set_value( v ) # 選択されない場合をnilで統一するため、ヌルストリングはnilへ変換する。 @value = (v == "") ? nil : v end |
#validate ⇒ Boolean
(AlSelector) バリデート
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 |
# File 'lib/al_form.rb', line 966 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 |