2011-03-13 118 views
0

也許有人知道。如何包裝Zend_Form_Element_Radio,包括整個無線電輸入堆棧的標籤(帶有輸入標籤)。在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); 

上面的例子沒的解決我的,因爲它僅包裝幾個輸入標籤的。

+1

你是什麼意思的包裝?你能提供一個你現在得到的html的例子,你想達到什麼目的? – Marcin 2011-03-13 23:20:19

回答

2

我想我知道你在追求什麼,如果是這樣,你很幸運,因爲我前幾天不得不這樣做。

標準ZF多選項元素使用separator屬性(默認爲<br />用於選擇radio和newline)分隔每個「選項」。對於<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版本應該很容易。

+0

正是我在尋找的東西。謝謝 :) – 2011-12-08 09:31:17