How to change comments data with onchange function in addfield in magento - magento

I created custom module and now from admin side on edit form i added extra field select type.
I want to change comments with onchange function for this specific field.See below my code.
$eventElem = $fieldset->addField('banner_type', 'select', array(
'label' => Mage::helper('multibanners')->__('Banner Style'),
'required' => false,
'onchange' => 'checkSelectedItem(this.value)',
'name' => 'banner_type',
'values' => array(
array(
'value' => 'Banner 1',
'label' => 'AnySlider',
),
array(
'value' => 'Banner 2',
'label' => 'Content Slider',
),
));
$eventElem->setAfterElementHtml("<script type=\"text/javascript\">function checkSelectedItem(selectElement){}</script>");
This is my code i alert the value and i got my value but it cannot show it in comments area .Did someone one know how to fix it ?
Thanks

This will update the comment (onchange) with the current selected option
$fieldset->addField('banner_type', 'select', array(
'label' => Mage::helper('multibanners')->__('Banner Style'),
'required' => false,
'onchange' => 'checkSelectedItem(this.value)',
'name' => 'banner_type',
'values' => array(
array(
'value' => 'Banner 1',
'label' => 'AnySlider',
),
array(
'value' => 'Banner 2',
'label' => 'Content Slider',
),
)
))->setAfterElementHtml("<small id='banner_type_comment'>Comments</small>
<script type=\"text/javascript\">
function checkSelectedItem(selectElement){
$('banner_type_comment').update($('banner_type')[$('banner_type').selectedIndex].text);
}
</script>");

Related

How to have 2 actions to action column in Magento grid?

I've created an action column in my magento grid but I want 2 actions in my action column.
I try this code in my _prepareColumn:
$this->addColumn('action',
array(
'header' => Mage::helper('sterenn_quote')->__('Action'),
'width' => '100px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('sterenn_quote')->__('Modidier'),
'url' => array(
'base' => '*/*/modifyquotation',
'param' => array('id' => $this->getRequest()->getParam('quotation_id'))
),
'field' => 'id'
),
array(
'caption' => Mage::helper('sterenn_quote')->__('Detail'),
'url' => array(
'base' => '*/*/detail',
'param' => array('id' => $this->getRequest()->getParam('quotation_id'))
),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores'
));
But I obtain this result :
How can I have my two action "Modifier" And "Detail" ?
Thanks for answers !

Yii1: How to force filter list in CGridView to parse html ?

I have a grid, in this grid I have filter. Grid code is:
$this->widget('booster.widgets.TbGridView', array(
'id' => 'sam',
'type' => 'striped bordered condensed',
'dataProvider' => $dataProvider,
'responsiveTable' => true,
'enableHistory' => true,
'filter' => $asset,
'columns' => array(
array(
'name' => 'id',
'header' => '#',
'filter' => false,
'type' => 'text',
),
array(
'name' => 'user',
'header' => 'Registered By',
'type' => 'text',
'value' => '$data["assignedBy"]',
),
array(
'name' => 'createdAt',
'header' => 'Created At',
'type' => 'datetime',
),
array(
'name' => 'serial',
'header' => 'Serial',
),
array(
'name' => 'brand',
'header' => 'Brand',
),
array(
'name' => 'model',
'header' => 'Model',
),
array(
'name' => 'assetType',
'type' => 'text',
'filter' => \wsi\it\model\AssetType::getRepository()->getTypeTree(),
'value' => '$data["assetTypeName"]',
'header' => 'Type',
),
array(
'name' => 'assigned',
'value' => '(isset($data["assignedTo"]))? $data["assignedTo"]:null',
'header' => 'Assigned To',
),
array(
'name' => 'location',
'filter' => \wsi\hr\Facade::getInstance()->getLocations(),
'value' => '$data["locationName"]',
'header' => 'Location',
),
array(
'name' => 'status',
'header' => 'Status',
'filter' => \wsi\it\model\Asset::$statusOptionList,
'value' => '\wsi\it\model\Asset::$statusOptionList[$data["status"]]',
),
array(
'class' => 'booster.widgets.TbButtonColumn',
'template' => '{view} {update} {delete}',
'header' => '',
'buttons' => array(
'update' => array(
'url' => '\Yii::app()->controller->createUrl("asset/create", array("id"=>$data["id"]))',
),
'view' => array(
'url' => '\Yii::app()->controller->createUrl("asset/view", array("id"=>$data["id"]))',
),
'delete' => array(
'url' => '\Yii::app()->controller->createUrl("asset/delete", array("id"=>$data["id"]))',
),
),
),
)
)
);
When Grid is rendered in the browser you can see that the filter list box contains html which is not parsed fully!
I had this problem with Yii-Booster before and I solved it with an option which I passed to that widget ('htmlOptions' => 'encode' => false) and It prevents to be treated as string, so browsers would parse it as space. That code which You can see below does not work for grid filter!
$form->dropDownListGroup($formModel, 'segmentList', array(
'wrapperHtmlOptions' => array(
'class' => 'col-md-6'
),
'widgetOptions' => array(
'data' => $segmentTreeArray,
'htmlOptions' => array(
>>> 'encode' => false, <<<
)
),
'hint' => "Press CTRL to add another item, otherwise others will be deselected",
));
BUT I am sure that I have to pass same "encode" => false to filter list too, I just can not find under what key I should pass it (htmlOptions did not work).

Display Action labes in single row instead of combobox in grid on admin side magento

I want to show Display Action labes in single row instead of combobox in grid on admin side magento .My code for combobox is
$this->addColumn('action',
array(
'header' => Mage::helper('mymodule')->__('Action'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('mymodule')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
),
array(
'caption' => Mage::helper('mymodule')->__('Delete'),
'url' => array('base'=> '*/*/delete'),
'confirm' => Mage::helper('mymodule')->__('Are you sure?'),
'field' => 'id'
),
array(
'caption' => Mage::helper('mymodule')->__('View'),
'url' => array('base'=> '*/*/view'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
See image for combobox style.
Checkout this code
$this->addColumn('actions', array(
'header' => Mage::helper('adminnotification')->__('Actions'),
'width' => '250px',
'sortable' => false,
'renderer' => 'adminhtml/notification_grid_renderer_actions',
));
under class Mage_Adminhtml_Block_Notification_Grid
and also see the class Mage_Adminhtml_Block_Notification_Grid_Renderer_Actions
If you have still any problem let me know.

set selected field when define with 'type' => 'select' in magento

I have a custom module where I create a form.
One field is a dropdown with values from a flat file.
$fields = array(
'type_of_service' => array('display' => 'Tip serviciu',
'required' => true,
'type' => 'select',
'options' => $serviceTypeOptions,
How can I set one value to be selected ?
EDIT:
if I use something like this in _prepareForm()
$fieldset->addField('select', 'select', array(
'label' => Mage::helper('tracking')->__('Select'),
'class' => 'required-entry',
'required' => true,
'name' => 'title',
'value' => '3',
'values' => array('-1'=>'Please Select..','1' => 'Option1','2' => 'Option2', '3' => 'Option3'),
)),
preselected will be 3.
But I generate my fields previously, and assign those to form with
$formFields = $this->getFormFields();
The problem is that I can't use the addField method, I need to have them created within my function.
Thanks.
try this,
'required' => true,
'value' => '2',
'values' => array(
array('1' => 'Option 1','2' => 'Option 2'),
...
which will select Option 2.
Try this
'required' => true,
'value' => 2,
'values' => array(
array('label' => 'Option 2', value => 2),
array('label' => 'Option 1', value => 1)
)
A full example can be like below
$fieldset->addField(
'target_type',
'select',
array(
'label' => $this->__("Target Type"),
'class' => 'required-entry',
'required' => 'true',
'name' => 'target_type',
'note' => $this->__("Target Type"),
'value' => 2,
'values' => array(
array(
'value' => 2,
'label' => 'Option 2'
)
)
)
);
NOTE : If you want to know about any of the Varien_Data_Form_Elements, you can directly do an inspection of Varien library /lib/Varien/Data/Form/Element/Select.php in your case.

Magento Custom module - how to add custom select box with parent categories

I wrote a module to have my own menu bar, rather than just using categories as a menu bar.
So, here I want to show already added menus while adding new menu in the Tab/Form.php in my custom menu module. How can I show all of the existing menu names as a dropdown/options list on the form. Here is the code that I used to have menu form.
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('menu_form', array('legend'=>Mage::helper('menu')->__('Menu information')));
$note = "Name of this Menu";
$fieldset->addField('title', 'text', array(
'label' => Mage::helper('menu')->__('Menu Name'),
'class' => 'required-entry',
'required' => true,
'note' => $note,
'name' => 'title',
));
$note = "Menu level";
$fieldset->addField('level', 'select', array(
'label' => Mage::helper('menu')->__('Menu level'),
'name' => 'level',
'note' => $note,
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Level 1'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Level 2'),
),
),
));
$model = Mage::registry('menu');
$fieldset->addField('parent', 'text', array(
'name' => 'conditions',
'label' => Mage::helper('menu')->__('Parent Menu'),
'title' => Mage::helper('menu')->__('Parent Menu'),
'required' => false,
'note' => $note,
))->setRule($model)->setRenderer(Mage::getBlockSingleton('rule/conditions'));
$fieldset->addField('target', 'select', array(
'label' => Mage::helper('menu')->__('Open in new window'),
'name' => 'target',
'values' => array(
array(
'value' => "_blank",
'label' => Mage::helper('menu')->__('Yes'),
),
array(
'value' => "_self",
'label' => Mage::helper('menu')->__('No'),
),
),
));
$fieldset->addField('status', 'select', array(
'label' => Mage::helper('menu')->__('Status'),
'name' => 'status',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Enabled'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Disabled'),
),
),
));
$note = "Menu Links to Which page. BaseURL(<b>".str_ireplace("index.php/","",Mage::getBaseUrl())."</b>) Will be Added Dynamically, Please add Your new page Refrence alone";
$fieldset->addField('menulink', 'text', array(
'label' => Mage::helper('menu')->__('URL'),
'required' => true,
'class' => 'required-entry',
'note' => $note,
'name' => 'menulink',
));
$fieldset->addField('position', 'select', array(
'label' => Mage::helper('menu')->__('Position'),
'name' => 'position',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Top 1'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Top 2'),
),
),
));
if ( Mage::getSingleton('adminhtml/session')->getMenuData() )
{
$form->setValues(Mage::getSingleton('adminhtml/session')->getMenuData());
Mage::getSingleton('adminhtml/session')->setMenuData(null);
} elseif ( Mage::registry('menu_data') ) {
$form->setValues(Mage::registry('menu_data')->getData());
}
return parent::_prepareForm();
In this I want to show all the added menus under the parent menu option. What should I write in my Model class so that I can have a drop down list to show them all, and after adding it should be added to database.
Please help me, am struggling here.
You can do this by adding these lines.
It will show already added menus as a dropdown list so that you can choose any of them as a parent menu for current item.
$_menus = Mage::getSingleton('menus/menus')->getCollection();
foreach($_menus as $item)
{
if($item->getParent == NULL){
$_menuItems[] = array(
'value' => $item->getId(),
'label' => $item->getTitle(),
);
}
}
$note = "Choose the parent menus for this item";
$fieldset->addField('parent', 'select', array(
'name' => 'parent',
'label' => Mage::helper('menus')->__('Parent Menu'),
'title' => Mage::helper('menus')->__('Parent Menu'),
'required' => false,
'note' => $note,
'class' => 'HideIt',
'values' => $_menuItems,
));

Resources