5

My class extends from Mage_Adminhtml_Block_Widget_Form, which has declaration for _prepareForm method with code for myfield as follows

  $fieldset->addField('myElementId', 'link', array(
      'label'     => 'myLabel',
      'href' => 'http://magento.stackexchange.com',
      'value'  => 'myElementValue'
    ));

This field is rendering all except value (i.e, myElementValue).

Can any one help me with this?

Billions of Thanks in Advance

EDIT:

My class name - MyNameSpace_MyModule_Block_Adminhtml_MyBlockGroup_ClassExtendingFormContainer_Tab_Form

This class defines the _prepareForm function as follows:

 protected function _prepareForm()
 {
       $form = new Varien_Data_Form();
       $this->setForm($form);
       $fieldset = $form->addFieldset('someElementId',array('key'=>'value'));          

      $fieldset->addField('myElementId', 'link', array(
                      'label'     => 'myLabel',
             'href' => 'http://magento.stackexchange.com/',
              'value'  => 'myElementValue',
            ));

      $fieldset->addField('myElementId2', 'text', array(
                    'label' => 'myLabel2',
                    'name' => 'myElementId2',
             ));

  $dateFormatIso = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
      $fieldset->addField('myElementId3', 'date', array(
                     'name'   => 'myElementId3',
                     'label'  => 'myLabel3',
                     'width'=>"100px",
                     'image'  => $this->getSkinUrl('images/grid-cal.gif'),
                     'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
                     'format'       => $dateFormatIso,
                     'time' => true, 
        ));

     if ( Mage::registry('SomeRegistrySetinCurrentControllerAction') )
     {
       $form->setValues(Mage::registry('SomeRegistrySetinCurrentControllerAction')->getData());
 }

 return parent::_prepareForm();
 }

It is rendering date, text fields in the form but not link.

  • 1
    Could you show us full class declaration. – mageUz Jun 6 '13 at 13:50
  • 1
    Your code is working fine on my end. We probably need a bit more/precise details. What happens when you change 'link' to 'text'? Will the value show in the text box? – Dan Jun 6 '13 at 13:59
  • @Homidjonov, i have edited my Question accordingly. – basha Jun 7 '13 at 5:42
  • @Dan, No, when i replace 'link' with 'text' value is rendered in TextField(i.e, TF is empty). – basha Jun 7 '13 at 5:46
  • @basha Your code is working fine except for form->addFieldset( should be $form->addFieldset, but I suspect that is just a typo here. So the only explanation, is to check your real code and make sure you don't have a typo somewhere. Like maybe, you have typed valeu instead of value. – Dan Jun 7 '13 at 7:41
2

Your code works (almost) correctly.
The value of the link field is not shown because it is overwritten by $form->setValues(...).
Here is how Varien_Data_Form::setValues() works

public function setValues($values)
    {
        foreach ($this->_allElements as $element) { //for each element in the form
            if (isset($values[$element->getId()])) {//if there is a value in the values for the element set the value of that element.
                $element->setValue($values[$element->getId()]);
            }
            else {//if there is no value for the element set its value to null.
                $element->setValue(null);
            }
        }
        return $this;
    }

I recommend using $form->addValues(...); this one does not set to null the missing values in the parameter passed to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.