Class: AlText
Overview
テキストウィジェット
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Integer) max
最大長さ.
-
- (Integer) min
最小長さ.
-
- (Regexp) validator
正規表現によるバリデータ。正常パターンを登録する。.
Instance Method Summary (collapse)
-
- (AlText) initialize(name, arg = {})
constructor
(AlText) constractor.
-
- (String) make_tag(arg = {})
(AlText) HTMLタグの生成.
-
- (Object) set_value(v)
(also: #value=)
(AlText) 値のセット.
-
- (Boolean) validate
(AlText) バリデート.
Methods inherited from AlWidget
Constructor Details
- (AlText) initialize(name, arg = {})
(AlText) constractor
677 678 679 680 681 682 |
# File 'lib/al_form.rb', line 677 def initialize( name, arg = {} ) super( name, arg ) @validator = arg[:validator] || /[^\x00-\x1F\x7F]/ @max = arg[:max] @min = arg[:min] end |
Instance Attribute Details
- (Integer) max
最大長さ
660 661 662 |
# File 'lib/al_form.rb', line 660 def max @max end |
- (Integer) min
最小長さ
663 664 665 |
# File 'lib/al_form.rb', line 663 def min @min end |
- (Regexp) validator
正規表現によるバリデータ。正常パターンを登録する。
657 658 659 |
# File 'lib/al_form.rb', line 657 def validator @validator end |
Instance Method Details
- (String) make_tag(arg = {})
(AlText) HTMLタグの生成
736 737 738 739 740 741 742 743 744 745 746 |
# File 'lib/al_form.rb', line 736 def make_tag( arg = {} ) if @hidden return %Q(<input type="hidden" name="#{@name}" id="#{@name}" value="#{Alone::escape_html( @value )}" #{AL_FORM_EMPTYTAG_CLOSE}\n) end r = %Q(<input type="text" name="#{@name}" id="#{@name}" value="#{Alone::escape_html( @value )}") (@tag_attr.merge arg).each do |k,v| r << %Q( #{k}="#{Alone::escape_html(v)}") end return "#{r} #{AL_FORM_EMPTYTAG_CLOSE}" end |
- (Object) set_value(v) Also known as: value=
(AlText) 値のセット
690 691 692 |
# File 'lib/al_form.rb', line 690 def set_value( v ) @value = v.to_s end |
- (Boolean) validate
(AlText) バリデート
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 |
# File 'lib/al_form.rb', line 701 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 |