Magento News
Magento configuration – populating field when using frontend_model
I have specified a frontend_model in system.xml for an entry field. I did this because I wanted to make a field read-only. There may have been a more straightforward way to achieve that, but that’s where I am at the moment. The thing is I cannot get the field to display the data it should.
I have a button that when pressed, populates the read-only field. That works fine. But when I hit ‘Save Config’, the data disappears from the field. The reason it disappears is because I can’t find out what I should set the field’s value to. Below tries using the getEscapedValue() method of Varien_Data_Form_Element_Abstract, but it returns nothing. And as usual with Magento, there is no documentation to speak of.
class Mypackage_MyModule_Block_Adminhtml_System_Config_DisabledText extends Mage_Adminhtml_Block_System_Config_Form_Field
{
protected function _prepareLayout()
{
parent::_prepareLayout();
if (!$this->getTemplate()) {
$this->setTemplate('mypackage/system/config/disabled_text.phtml');
}
return $this;
}
public function render(Varien_Data_Form_Element_Abstract $element)
{
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
$originalData = $element->getOriginalData();
$this->addData(array(
'my_value' => $element->getEscapedValue(),
'html_id' => $element->getHtmlId(),
));
return $this->_toHtml();
}
}
disabled_text.phtml contains the following:
<input id="<?php echo $this->getHtmlId() ?>" value="<?php echo $this->getMyValue(); ?>" class=" input-text" type="text" disabled/>
Thanks.
Magento configuration – populating field when using frontend_model
Possibly Related Posts:
- Database query different results
- Menu highlight in magento under admin
- magento disable a banner on certain category pages or have a banner with multiple links
- Magento, using ACL for frontend. Possible?
- Magento IE-7 Fix In Windows XP
RSS Feed