I have a custom module in admin, where I am display values in dropdown format something like below using addField function.
<select onchange="checkSelectedBean(this.value)" class="required-entry select" name="nic_id" id="nic_id">
<option value="-1">Please Select</option>
<option value="1_1.1">America</option>
<option value="2_2.2">China</option>
<option value="3_3.3">India</option>
<option value="4_4.4">Japan</option>
</select>
Here 4 is the ID for Japan and 4.4 is its unique value.
Now, If I select Japan as an option and save it, I have split the post value i.e. 4_4.4 and the value saved in DB is 4 which is okay. But when I edit the same record its not showing me the saved option Japan but dropdown list of all options.
I need to know how can I make Japan as selected option in dropdown, when admin edits the same record.
Right now its showing me the dropdown list only and not the saved option.
I am fetching value from my Model/Nic.php like below.
public function toOptionArray()
{
$nicCollection = Mage::getModel('nic/nic')->getCollection();
$nicarray = array(array('value'=>-1, 'label'=>'Please Select'));
foreach ($nicCollection as $nicList){
$nicarray[] = array('value'=>$nicList['nic_id']._.$nicList['nic_cost'],'label'=>$nicList['nic_name']);
}
return $nicarray;
}
Admin form to fetch selected dropdown with values
$fieldset->addField('nic_id', 'select', array(
'label' => Mage::helper('nic')->__('Nic'),
'class' => 'required-entry',
'values' => Mage::getModel('nic/nic')->toOptionArray(),
'name' => 'nic_id',
));
Pls Help.
Thanks.