Class: AlText
Overview
テキストウィジェット
Direct Known Subclasses
Instance Attribute Summary collapse
-
#max ⇒ Integer
最大長さ.
-
#min ⇒ Integer
最小長さ.
-
#validator ⇒ Regexp
正規表現によるバリデータ。正常パターンを登録する。.
Attributes inherited from AlWidget
#filter, #foreign, #hidden, #label, #message, #name, #required, #tag_attr, #tag_type, #value
Instance Method Summary collapse
-
#initialize(name, arg = {}) ⇒ AlText
constructor
(AlText) constructor.
-
#set_value(v) ⇒ Object
(also: #value=)
(AlText) 値のセット.
-
#validate ⇒ Boolean
(AlText) バリデート.
Methods inherited from AlWidget
#make_tag, #make_value, #set_attr
Constructor Details
#initialize(name, arg = {}) ⇒ AlText
(AlText) constructor
755 756 757 758 759 760 |
# File 'lib/al_form.rb', line 755 def initialize( name, arg = {} ) super( name, arg ) @validator = arg[:validator] || /[^\x00-\x1F\x7F]/ @max = arg[:max] @min = arg[:min] end |
Instance Attribute Details
#max ⇒ Integer
Returns 最大長さ.
739 740 741 |
# File 'lib/al_form.rb', line 739 def max @max end |
#min ⇒ Integer
Returns 最小長さ.
742 743 744 |
# File 'lib/al_form.rb', line 742 def min @min end |
#validator ⇒ Regexp
Returns 正規表現によるバリデータ。正常パターンを登録する。.
736 737 738 |
# File 'lib/al_form.rb', line 736 def validator @validator end |
Instance Method Details
#set_value(v) ⇒ Object Also known as: value=
(AlText) 値のセット
768 769 770 |
# File 'lib/al_form.rb', line 768 def set_value( v ) @value = v.to_s end |
#validate ⇒ Boolean
(AlText) バリデート
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 |
# File 'lib/al_form.rb', line 779 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 |