How do i remove the label decorator from a submit button
Asked Answered
E

4

10

In my form i have this code;

// Add the submit button
$element = $this->addElement('submit', 'submit', array(
    'ignore'   => true,
    'label' => 'Add new material'
));
$element->removeDecorator('label');

However the form still renders with the label element between the tags.

What am i doing wrong?

Exceed answered 28/7, 2009 at 19:23 Comment(0)
K
17

This worked for me:

$this->addElements(array(  
  new Zend_Form_Element_Submit('submit', array(  
    'label' => 'Save'  
  ))  
));  
$element = $this->getElement('submit');  
$element->removeDecorator('DtDdWrapper');

I did print_r($element); to find out what decorators exist for $element.

Kacerek answered 8/3, 2010 at 18:55 Comment(0)
S
11

The function addElement returns a reference to the current form not to the last added element.

You could try this:

$form = new Zend_Form();
$form->addElement('submit', 'submit', array(
    'ignore'   => true,
    'label'     => 'Add new material'
));

$element = $form->getElement('submit');
$element->removeDecorator('label');
Splatter answered 4/8, 2009 at 11:24 Comment(1)
Also Zend_Db_Element has no function addElement Zend_Db_Form hasSplatter
C
3

I think the argument to removeDecorator is case-sensitive. I.e., it should be "Label" # note the uppercase 'L'.

Costanzia answered 28/7, 2009 at 21:55 Comment(2)
I tried that it doesn't make any difference. I found this in another answer, but it doesn't seem right to do it this way as it is not how the documentation descibes how to do it. $element->removeDecorator('DtDdWrapper')->addDecorator('HtmlTag', array('tag' => 'dd')); However, even removing the <dt> element from the html did not solve my overall issue of not being able to position the submit button hard to the left.Exceed
So, you changed this: $element->removeDecorator('label'); to this: $element->removeDecorator('Label'); and it still didn't work? If that's the case perhaps try var_dump(getDecorators()) and let's go from there.Costanzia
P
1

To overcome this nuisance I'm defining manually the decorators for my element...

$details->addElement('text', 'in_year', array(
    'decorators'=>array(
    'ViewHelper',
    array('HtmlTag', array('tag' => 'span')),
    )
));

You can of course define your own tags. In this example I only initialise the "ViewHelper" decorator. If I want to initialise the "Label" decorator I would do:

$details->addElement('text', 'in_year', array(
    'decorators'=>array(
    'ViewHelper',
    'Label',
    array('HtmlTag', array('tag' => 'span')),
    ),
    'attribs' => array('class' => 'required validate-digits')
));

I hope this makes sense... :o)

Palpebrate answered 20/8, 2009 at 8:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.