Class: AlWidget

Inherits:
Object
  • Object
show all
Defined in:
lib/al_form.rb

Overview

ウィジェット スーパークラス

Direct Known Subclasses

AlFile, AlNumber, AlSelector, AlSubmit, AlText, AlTimestamp

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (AlWidget) initialize(name, arg = {})

(AlWidget) constractor

Parameters:

  • (String) name

    ウィジェット識別名 英文字を推奨

  • (Hash) arg (defaults to: {})

    引数ハッシュ

Options Hash (arg):

  • (String) :label N/A

    ラベル文字列

  • (Object) :value N/A

    初期値

  • (Boolean) :required N/A

    必須入力フラグ

  • (String) :filter N/A

    入力値フィルター

  • (Hash) :tag_attr N/A

    htmlタグ要素の追加アトリビュート

  • (Boolean) :foreign N/A

    値が外部で生成されるかのフラグ

  • (Boolean) :hidden N/A

    hiddenタグとして生成するかのフラグ



597
598
599
600
601
602
603
604
605
606
607
# File 'lib/al_form.rb', line 597

def initialize( name, arg = {} )
  @name = name.to_s
  @label = arg[:label] || @name
  @value = arg[:value]        # (note) 初期値にはfilterをかける必要はないだろう
  @required = arg[:required] ? true: false
  @filter = arg[:filter]
  @tag_attr = arg[:tag_attr] || {}
  @foreign = arg[:foreign] ? true : false
  @hidden = arg[:hidden] ? true : false
  @message = ""
end

Instance Attribute Details

- (String) filter

入力フィルター

Returns:

  • (String)

    入力フィルター



569
570
571
# File 'lib/al_form.rb', line 569

def filter
  @filter
end

- (Boolean) foreign (readonly)

値が外部で生成されて、フォーム入力ではない事を示すフラグ

Returns:

  • (Boolean)

    値が外部で生成されて、フォーム入力ではない事を示すフラグ



575
576
577
# File 'lib/al_form.rb', line 575

def foreign
  @foreign
end

- (Boolean) hidden

HTMLタグ input type=“hidden” として生成するかのフラグ

Returns:

  • (Boolean)

    HTMLタグ input type=“hidden” として生成するかのフラグ



578
579
580
# File 'lib/al_form.rb', line 578

def 
  @hidden
end

- (String) label

ラベル

Returns:

  • (String)

    ラベル



560
561
562
# File 'lib/al_form.rb', line 560

def label
  @label
end

- (String) message (readonly)

メッセージ

Returns:

  • (String)

    メッセージ



581
582
583
# File 'lib/al_form.rb', line 581

def message
  @message
end

- (Symbol) name (readonly)

識別名

Returns:

  • (Symbol)

    識別名



557
558
559
# File 'lib/al_form.rb', line 557

def name
  @name
end

- (Boolean) required (readonly)

必須入力フラグ

Returns:

  • (Boolean)

    必須入力フラグ



566
567
568
# File 'lib/al_form.rb', line 566

def required
  @required
end

- (Hash) tag_attr

Htmlタグ生成時のアトリビュート

Returns:

  • (Hash)

    htmlタグ生成時のアトリビュート



572
573
574
# File 'lib/al_form.rb', line 572

def tag_attr
  @tag_attr
end

- (Object) value

入力値または初期値

Returns:

  • (Object)

    入力値または初期値



563
564
565
# File 'lib/al_form.rb', line 563

def value
  @value
end

Instance Method Details

- (String) make_value(*arg)

Note:

make_tag()との対称性をもたせるために存在する。

(AlWidget) HTML値の生成

Parameters:

  • (String) arg

    表示値。指定なければ内部値を使う。

Returns:

  • (String)

    html文字列



643
644
645
# File 'lib/al_form.rb', line 643

def make_value( *arg )
  return Alone::escape_html( arg.empty? ? @value: arg[0] )
end

- (Object) set_attr(arg)

Note:

名称はsetだが、実質はaddである。 一貫していないようだが、テンプレートとの兼ね合いもあり、 この名称の方が自然に記述できる。

(AlWidget) アトリビュートの設定

Parameters:

  • (Hash) arg

    セットする値



630
631
632
# File 'lib/al_form.rb', line 630

def set_attr( arg )
  @tag_attr.merge!( arg )
end

- (Object) set_value(v) Also known as: value=

(AlWidget) 値のセット

Parameters:

  • value

    セットする値



615
616
617
# File 'lib/al_form.rb', line 615

def set_value( v )
  @value = v
end