2010-08-03 40 views
1

我有兩種形式,他們共享一些ID,因爲兩個輸入字段被稱爲'標題'。Zend Decorators - 刪除DT包裝的Id字段

Zend公司產生了我一個很好的輸出是這樣的:

<dl class="zend-form"> 
    <dt id="title-label"> 
    <label for="form1-title" class="required">Description</label> 
    </dt> 
    <dd id="title-element"> 
    <input name="form1[title]" id="form1-title" value="..." type="text"> 
    </dd> 
</dl> 

現在的問題是,DT和DD元素命名錯誤(應該是Form1的標題 - 拉布勒因爲這是一個子表單)。

我也試圖改變元素裝飾:

$this->addElements(...); 
$this->setElementDecorators(array(
     'ViewHelper', 
     'Errors', 
     array(array('data' => 'HtmlTag'),array('tag' => 'dd', 'class' => 'element')), 
     array(array('data' => 'Label'),array('tag' => 'dt', class=> 'label')) 
)); 

但是不符合預期的結果。

一個標籤被添加到我的提交按鈕和 dt元素的id仍然存在。

如何刪除id屬性?


編輯 - 元素聲明:

$titel = new Zend_Form_Element_Text('title'); 
    $titel->setLabel("Title") 
      ->addValidator('NotEmpty', true) 
      ->addValidator('stringLength',true, array(0, 255)) 
      ->setRequired(true) 
      ->addFilter("Alnum", array(true)) 
      ->addFilter('StringTrim'); 

    $this->addElement($titel); 
+1

你使用子表單嗎?你能發佈這個元素的整個代碼嗎? – 2010-08-17 14:41:20

回答

1

這聽起來更像是你的子表單中的問題不是將它們的名稱預先添加到ID中。如果你解決了這個問題,那麼你不需要刪除這些ID。

但是,如果您想使用DtDdWrapper裝飾器從元素中移除ID,則可以這樣做。

class Form_Foo extends Zend_Form_SubForm 
{ 
    public function init() 
    { 

     $title = new Zend_Form_Element_Text('foo_title'); 
     $title->setLabel('Title'); 
     $title->removeDecorator('DtDdWrapper'); 
     $title->addDecorator(new Decorator_Foo());  
     $this->addElement($title); 
    } 
} 

class Decorator_Foo extends Zend_Form_Decorator_DtDdWrapper 
{ 
    public function render($content) 
    { 
     return '<dt>&nbsp;</dt>' . 
       '<dd>' . $content . '</dd>'; 
    } 
} 

這應該給你沒有ID標籤的元素。

0

您可以創建自定義標籤裝飾讓您可以修改默認渲染功能。

class App_Form_Decorator_Label extends Zend_Form_Decorator_Label 
{ 

    public function render() 
    { 
     // Insert here the render function of Zend_form_Decorator_Label but without the id decorator. 
    } 
}