2

Hi i used this code to add button in custom module in magento admin.

I need to create a "Run Now" button and my code created a button without text. Like screenshot:

enter image description here

My question is : how to add "Run Now" text on button?

File: system.xml

<enabled translate="label">
                            <label>Enable Module</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </enabled>

<module_btn translate="label">
                <depends><enabled>1</enabled></depends>
                <label>Product Button</label>
                <frontend_type>button</frontend_type>
                <frontend_model>weo_productlist/adminhtml_system_config_button</frontend_model>
                <sort_order>2</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>0</show_in_website>
                <show_in_store>0</show_in_store>
            </module_btn>

Here is the code of /adminhtml_system_config_button file:

<?php
class Weo_Productlist_Block_Adminhtml_System_Config_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
{


protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {       
        $html = parent::_getElementHtml($element);
        $this->setElement($element);

        $html = $this->getLayout()->createBlock('adminhtml/widget_button')
                    ->setType('button')
                    ->setClass('scalable1')
                    ->setLabel('Run Now')
                    ->setOnClick("return callajaxRequestController();")
                    ->toHtml();


       return $html;





    }

}
  • i think change label value <label>Product Button</label> – Yogesh Nov 15 '17 at 11:15
  • @Yogesh its add label to button, not text on button. – pooja Nov 15 '17 at 11:18
  • @pooja add code of your weo_productlist/adminhtml_system_config_button file – Piyush Nov 15 '17 at 11:35
  • @Piyush i updated the code of weo_productlist/adminhtml_system_config_button file. – pooja Nov 15 '17 at 11:39
  • @pooja check my answer and let me know if any issue – Piyush Nov 15 '17 at 11:41
0

To change button label you have to change setLabel value in file Weo_Productlist_Block_Adminhtml_System_Config_Button

$html = $this->getLayout()->createBlock('adminhtml/widget_button')
                    ->setType('button')
                    ->setClass('scalable1')
                    ->setLabel('Run Now') // change your label here
                    ->setOnClick("return callajaxRequestController();")
                    ->toHtml();
| improve this answer | |
  • yes i did it. but by this code <depends><enabled>1</enabled></depends> tag not working. i need to hide the button if "Enable Module" field value set to "No". If i commented above code in "Weo_Productlist_Block_Adminhtml_System_Config_Button" file , button is shows without label. – pooja Nov 15 '17 at 11:44
  • @pooja that code is fine, if it is not working confirm the field name <enabled>. Also mark this answer as accepted if it helped you – Piyush Nov 15 '17 at 11:48
  • Please check my updated system.xml file code. – pooja Nov 15 '17 at 11:52
  • @pooja your code looks fine. is it displaying button when enabled is No ? – Piyush Nov 15 '17 at 12:00
  • 1
    thank you. i did it by adding an hidden field, Please check this answer: magento.stackexchange.com/questions/65246/… – pooja Nov 16 '17 at 4:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.