0

多分誰かが知っています。ラジオ入力のスタック全体のラベルを含む Zend_Form_Element_Radio をラップする方法 (入力ラベル付き)。

public $radioDecorators = array(
    'ViewHelper',
    array('Description',array('tag'=>'div','class'=>'','placement' => 'prepend')),
    array('Errors',array('class'=>'error_message_show','placement' => 'prepend')),
    array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'element')),
    array('label', array('class'=>'label_text','placement' => 'prepend')),
    array(array('rows' => 'HtmlTag'), array('tag' => 'div', 'class' => 'radio')),
);


    $offer_type = new Zend_Form_Element_Radio('offer_type', array(
                'label' => 'Label I'd like to wrap with inputs',    //Label to wrap
                'required' => true,
                'description' => '',
                'decorators' => $this->radioDecorators,
                'multioptions' => array (
                    'standard' => 'standard',
                    'premium' => 'premium',
                ),
            ));
    $this->addElement($offer_type);

上記の例は、いくつかの入力ラベルのみをラップするため、解決できませんでした。

4

1 に答える 1

2

私はあなたが何を求めているか知っていると思います。もしそうなら、先日これをしなければならなかったので、あなたは幸運です.

標準の ZF multi-option 要素は、プロパティを使用して各「オプション」を区切りseparatorます (ラジオの場合はデフォルト<br />、選択の場合は改行)。これは<option>要素には問題ありませんが、ラジオ ボタンのコレクションにはかなり手抜きです。

解決策は

  • HtmlTag デコレータを要素に追加し、コンテンツをラップします
  • セパレーターを設定して、HtmlTag を閉じて再度開く

たとえば、入力のコレクションを順序付けられていないリストにラップするソリューションは次のとおりです。

$offer_type = new Zend_Form_Element_Radio('offer_type', array(
    'separator' => '</li><li>',
    'decorators' => array(
        'ViewHelper',
        array(array('liWrapper' => 'HtmlTag'), array('tag' => 'li')),
        array(array('ulWrapper' => 'HtmlTag'), array('tag' => 'ul')),
        // the rest
    )
));

別の方法は、独自のビュー ヘルパーを作成することです。の独自のバージョンを作成するのformRadioは非常に簡単です。

于 2011-03-13T23:56:35.483 に答える