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, #value_format
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
946 947 948 949 950 951 |
# File 'lib/al_form.rb', line 946 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
-
選択項目のハッシュ
932 933 934 |
# File 'lib/al_form.rb', line 932 def @options end |
#separator ⇒ Object (readonly)
- String
-
HTMLタグを生成する場合のタグ間セパレータ
935 936 937 |
# File 'lib/al_form.rb', line 935 def separator @separator end |
Instance Method Details
#make_tag(appendix_tag = {}) ⇒ String
Note:
フラグ @hidden の時のみ対応。その他はサブクラスへ委譲。appendix_tagは使わない
(AlSelector) HTMLタグの生成
998 999 1000 1001 1002 1003 1004 1005 1006 |
# File 'lib/al_form.rb', line 998 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値の生成
1015 1016 1017 1018 1019 1020 1021 |
# File 'lib/al_form.rb', line 1015 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) 値のセット
959 960 961 962 |
# File 'lib/al_form.rb', line 959 def set_value( v ) # 選択されない場合をnilで統一するため、ヌルストリングはnilへ変換する。 @value = (v == "") ? nil : v end |
#validate ⇒ Boolean
(AlSelector) バリデート
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 |
# File 'lib/al_form.rb', line 971 def validate() @message = "" if @value == "" || @value == nil if @required @message = p_("al", "Please select %s.") % @label return false end return true end if ! @options[@value.to_sym] && ! @options[@value.to_s] && ! @options[@value.to_i] @message = p_("al", "The input for %s is not a valid value.") % @label return false end return true end |