【发布时间】:2014-10-15 20:48:48
【问题描述】:
这是一个管理表单,我在其中添加了一个自定义选项卡,以便向其中添加一些自定义字段。表格工作正常。但我需要为我的一些字段添加field dependency。
如果zipbasedprice_isrange字段设置为yes,则需要显示其他两个字段,如果设置为no,则只显示一个字段。
我怎样才能使用下面的表格来实现呢?
字段依赖关系应在zipbasedprice_isrange、zipbasedprice_zip、zipbasedprice_zip_from_zip 和zipbasedprice_zip_to_zip 之间。
public function getFormHtml() {
$form = new Varien_Data_Form(
array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post')
);
$this->getLayout()->createBlock('adminhtml/widget_form_renderer_element').
$this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset').
$this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element');
$fieldset = $form->addFieldset('zipbasedprice_fields', array('legend' => Mage::helper('zipbasedprice')->__('Zip Based Price'))
);
$default_country = array('label' => 'IN', 'code' => 'India');
$fieldset->addField('zipbasedprice_country', 'select', array(
'name' => 'zipbasedprice_country',
'label' => Mage::helper('zipbasedprice')->__('Country'),
'values' => Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(),
'required' => true,
'style' => 'width:275px',
'value' => $default_country,
'after_element_html' => '<p class="zipbased_comment" style="margin: 0 150px; padding: 3px;"><img style="margin-right: 4px;" src="http://zonepricing.innoexts.com/skin/adminhtml/default/default/images/note_bg.gif" /><small>select the country to apply price</small></p>',
));
$regions = array();
$regions['*'] = '*';
$regionList = Mage::getModel('directory/region')->getResourceCollection()->addCountryFilter('IN')->load();
foreach($regionList as $region){ $regions[$region['code']] = $region['default_name']; }
$fieldset->addField('zipbasedprice_state', 'select', array(
'name' => 'zipbasedprice_state',
'label' => Mage::helper('zipbasedprice')->__('Region/State'),
'values' => $regions,
'required' => true,
'style' => 'width:275px',
));
$isRange = $fieldset->addField('zipbasedprice_isrange', 'select', array(
'name' => 'zipbasedprice_isrange',
'label' => Mage::helper('zipbasedprice')->__('Is Range?'),
'values' => array(
array(
'value' => false,
'label' => Mage::helper('zipbasedprice')->__('No'),
),
array(
'value' => true,
'label' => Mage::helper('zipbasedprice')->__('Yes'),
)
),
'value' => false,
'onchange' => 'onIsZipRangeChange()',
'required' => false,
'style' => 'width:275px',
));
$fieldset->addField('zipbasedprice_zip', 'text', array(
'name' => 'zipbasedprice_zip',
'label' => Mage::helper('zipbasedprice')->__('Zip Code'),
'class' => 'input',
'required' => true,
'style' => 'width:268px',
'value' => '*',
'maxlength' => 6,
));
$fieldset->addField('zipbasedprice_zip_from_zip', 'text', array(
'name' => 'zipbasedprice_zip_from_zip',
'label' => Mage::helper('zipbasedprice')->__('Zip Code From'),
'class' => 'input',
'required' => true,
'style' => 'width:268px',
'value' => '*',
'maxlength' => 6,
));
$fieldset->addField('zipbasedprice_zip_to_zip', 'text', array(
'name' => 'zipbasedprice_zip_to_zip',
'label' => Mage::helper('zipbasedprice')->__('Zip Code To'),
'class' => 'input',
'required' => true,
'style' => 'width:268px',
'value' => '*',
'maxlength' => 6,
));
$fieldset->addField('zipbasedprice_price', 'text', array(
'name' => 'zipbasedprice_price',
'label' => Mage::helper('zipbasedprice')->__('Price'),
'class' => 'input',
'required' => true,
'style' => 'width:268px',
'value' => '0.00',
));
$fieldset->addField('zipbasedprice_apply', 'select', array(
'label' => Mage::helper('zipbasedprice')->__('Apply'),
'name' => 'zipbasedprice_apply',
'required' => false,
'values' => array(
array(
'value' => 'fixed',
'label' => Mage::helper('zipbasedprice')->__('Fixed'),
),
array(
'value' => 'percentage',
'label' => Mage::helper('zipbasedprice')->__('Percentage'),
)
),
'required' => 1,
'value' => 1,
'style' => 'width:275px',
));
return $form->toHtml();
}
【问题讨论】: