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, #value_format
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
760 761 762 763 764 765 |
# File 'lib/al_form.rb', line 760 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 最大長さ.
744 745 746 |
# File 'lib/al_form.rb', line 744 def max @max end |
#min ⇒ Integer
Returns 最小長さ.
747 748 749 |
# File 'lib/al_form.rb', line 747 def min @min end |
#validator ⇒ Regexp
Returns 正規表現によるバリデータ。正常パターンを登録する。.
741 742 743 |
# File 'lib/al_form.rb', line 741 def validator @validator end |
Instance Method Details
#set_value(v) ⇒ Object Also known as: value=
(AlText) 値のセット
773 774 775 |
# File 'lib/al_form.rb', line 773 def set_value( v ) @value = v.to_s end |
#validate ⇒ Boolean
(AlText) バリデート
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 |
# File 'lib/al_form.rb', line 784 def validate() @message = "" if @value == "" || @value == nil if @required @message = p_("al", "%s is required.") % @label return false end return true end if @max && @value.length > @max @message = p_("al", "%1$s must be entered within %2$d characters.") % [@label, @max] return false end if @min && @value.length < @min @message = p_("al", "%1$s must be at least %2$d characters long.") % [@label, @min] return false end if @validator !~ @value @message = p_("al", "Please enter %s correctly.") % @label return false end return true end |