How to add a button in admin form? - magento

I have add a button within admin form as follows.
$fieldset->addField('registered', 'button', array(
'label' => Mage::helper('core')->__('Send e-mail to all registered customers'),
'value' => Mage::helper('core')->__('Button Caption'),
'name' => 'registered',
'onclick' => "setLocation('{$this->getUrl('*/*/registeremail')}')",
));
The functionality of this field working properly but the button does not appear properly. It appears as follows.
How to appear this button as normal magento button?
I have tried with
'after_element_html' => '<button type="button" onclick="setLocation('{$this->getUrl('*/*/registeremail')}')">All Registered</button>'
But onclick call is wrong.

Try
$fieldset->addField('registered', 'button', array(
'label' => Mage::helper('core')->__('Send e-mail to all registered customers'),
'value' => Mage::helper('core')->__('Button Caption'),
'name' => 'registered',
'class' => 'form-button',
'onclick' => "setLocation('{$this->getUrl('*/*/registeremail')}')",
));
This works for me.

Related

Add input field in Magento Admin Panel

How can I add an <input type ="text"/> field in below screen shot of Magento Admin Panel to receive a value??
Thanks
Suppose you want to add "Title field".
You have to add following code on this file i.e. Am/Blog/Block/Adminhtml/Blog/Edit/Tab/Form.php
$fieldset->addField('title', 'text', array(
'label' => Mage::helper('blog')->__('Title'),
'class' => 'required-entry',
'required' => true,
'name' => 'title',
));

codeigniter bootstrap modal popup

I have used bootstrap modal popup in my site. By clicking the button pop will open. It is working on the following code.
HTML:
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
But the button come from array.
<?php
$args['test'] = array(
array(
'type' => 'submit',
'id' => ' text',
'label' => 'Launch demo modal',
'desc' => site_url('test'),
'class' => 'span3',
'default' => '',
'options' => ''),
);
?>
How can I pass "data-toggle="modal" data-target="#myModal" in array.
Nothing different, just add those attributes in the array like this:
array(
'type' => 'submit',
'id' => ' musicfileupload',
'label' => 'Launch demo modal',
'desc' => site_url('test'),
'class' => 'span3',
'default' => '',
'options' => '',
'data-toggle' => 'modal', // <--
'data-target' => '#myModal' // <--
);
Update: Following is a working example:
$data = array(
'type' => 'submit',
'id' => ' musicfileupload',
'label' => 'Launch demo modal',
'desc' => site_url('test'),
'class' => 'span3',
'default' => '',
'options' => '',
'data-toggle' => 'modal', // <--
'data-target' => '#myModal' // <--
);
echo form_button($data);

Using CakePHP form validation with angular JS

I am building a simple invoice module using angular js and cake php.
The items fields are repeated using ng - repeat in my view as seen below
<div ng:controller="ItemsCtrl" ng:app>
<div class="row-fluid items" >
<hr>
<ul class="invoice_items" ng:init="invoice={items:[{serial:'',details:'',qty:0,unit:'',rate:0,discount:0,amount:0}],pf:0}">
<li ng:repeat="item in invoice.items">
<div class="clear"></div>
<div id="items_row">
<div class="field span1">
<?php
echo $this->TwitterBootstrap->input("Number", array(
"input" => $this->Form->text("Item.{{\$index}}.serial" , array('class' => 'serial span1' ,'placeholder' => 'S.No' , 'ng-model' => 'item.serial' , 'value' => '{{ $index + 1 }}' , 'readonly' => 'readonly' ))
)); ?>
</div>
Closing the appropriate tags in the end
I have the following code in my model for validation -
public $validate = array(
'id' => array(
'notempty' => array(
'rule' => array('notempty'),
),
),
'serial' => array(
'notempty' => array(
'rule' => array('notempty'),
),
),
'details' => array(
'notempty' => array(
'rule' => array('notempty'),
),
),
'quantity' => array(
'notempty' => array(
'rule' => array('notempty'),
),
'naturalnumber' => array(
'rule' => array('naturalnumber'),
'message' => 'Please enter a valid quantity'
),
),
'rate' => array(
'notempty' => array(
'rule' => array('notempty'),
),
'numeric' => array(
'rule' => array('numeric'),
),
),
'discount' => array(
'numeric' => array(
'rule' => array('numeric'),
),
),
'amount' => array(
'notempty' => array(
'rule' => array('notempty'),
),
'numeric' => array(
'rule' => array('numeric'),
),
),
);
The issue is that the fields which are outside of the ng-repeat directive get validated as required , but since the fields inside ng-repeat get initialized on each page load, cakephp validation isnt applied to them .
Do you guys see any work around to this ? May be my entire architecture approach is wrong?
I think you should change the way you are solving the problem.
Use CakePHP to create a REST API and AngularJS for the frontend. It will be much easier (and better if you want to migrate your stack in the future, i.e. Dart or NodeJS).
You might want to read: https://github.com/hantsy/angularjs-cakephp-sample
Hope it helps.

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.

How to change comments data with onchange function in addfield in 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>");

Resources