Magento后端,捕获不同元素上的onclick事件 [英] Magento backend, capture onclick events on different elements

查看:181
本文介绍了Magento后端,捕获不同元素上的onclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有各种表单的工作后端模块来管理几个不同的表。在其中一个表单中,我有一个单选按钮组(Magento上的 radios 元素)。这是这个广播组的代码片段:

  // radio group 
$ fieldset-> addField(' radio_group','radios',array(
'label'=> Mage :: helper('banners') - > __('Select campaign type'),
'name'=> 'title',
'onclick'=>'',
'onchange'=>'',
'value'=>'1',
'values '=>数组(
array('value'=>'1','label'=>'Imagen'),
array('value'=>'2' ('value'=>'3','label'=>'Product'),
),
'disabled' => false,
'readonly'=> false,
'tabindex'=> 3
));

我无法找到如何管理 onclik onchange 事件。我需要在哪里添加代码?要执行的动作很简单,我只是根据所选的单选按钮启用/禁用同一页面上的其他控件。



任何建议,示例代码,教程?我做了大量的搜索工作,没有运气,我发现了很多样本​​,但都提到了如何设置一个新的管理员表单,至此我已经做了好几次了。解决此问题的一种方法是将update layout.xml添加到您的模块(或local.xml)中。

p>

您可以使用两种不同的方法将您的js包含在layout.xml中,唯一不同的是您需要将js文件放在哪里



Javascript位置:/js/your_js_file.js

 < adminhtml_xxx_yyy> 
< reference name =head>
< action method =addJs>< script> your_js_file.js< / script>< / action>
< / reference>
< / adminhtml_xxx_yyy>



Javascript位置:/ skin /adminhtml/default/default/your_js_file.js

 < adminhtml_xxx_yyy> 
< reference name =head>
< action method =addItem>< type> skin_js< / type>< name> your_js_file.js< / name>< / action>
< / reference>
< / adminhtml_xxx_yyy>

为每个单选按钮添加一个css类名称

  $ fieldset-> addField('radio_group','radios',array(
......
'class'=>' campaign_type',
....
));

在your_js_file.js( http://fiddle.jshell.net/hX2u3/

  $ $('。campaign_type')。each(function(curInput){
Event.observe(curInput,'click',function(){
alert('点击逻辑到这里');
$ b);
Event.observe(curInput,'change',function(){
alert('some change logic goes here');
});
} );


I've a working backend module with various forms to manage several different tables. On one of the forms I have a radio button group (radios element on Magento). Here is the code snippet for this radio group:

//radio group
$fieldset->addField('radio_group', 'radios', array(
        'label'     => Mage::helper('banners')->__('Select campaign type'),
        'name'      => 'title',
        'onclick'   => '',
        'onchange'  => '',
        'value'     => '1',
        'values'    => array(
                        array('value'=>'1','label'=>'Imagen'),
                        array('value'=>'2','label'=>'HTML'),
                        array('value'=>'3','label'=>'Producto'),
                        ),
        'disabled'  => false,
        'readonly'  => false,
        'tabindex'  => 3
));

There is no way I can find how to manage the onclik and the onchange events. Where do I need to add the code? The actions to be executed are simple, I'll just enable/disable other controls on the same page according to the selected radio button.

Any suggestion, sample code, tutorial? I've done lot of googling with no luck, I've found lot of samples but all refered to how to setup a new admin form, wich I have already done not once but several times.

解决方案

One way you could get around this issue is by adding update layout.xml to your module (or a local.xml)

You can include your js in layout.xml using two different method, the only different is where you need to put your js file

Javascript location : /js/your_js_file.js

<adminhtml_xxx_yyy>
    <reference name="head">
        <action method="addJs"><script>your_js_file.js</script></action>
    </reference>
</adminhtml_xxx_yyy>

or

Javascript location : /skin/adminhtml/default/default/your_js_file.js

<adminhtml_xxx_yyy>
    <reference name="head">
        <action method="addItem"><type>skin_js</type><name>your_js_file.js</name></action>
    </reference>
</adminhtml_xxx_yyy>

Add a css class name to each radio button

$fieldset->addField('radio_group', 'radios', array(
   ......
   'class'     => 'campaign_type',
   ....
));

In your_js_file.js ( http://fiddle.jshell.net/hX2u3/ )

$$('.campaign_type').each(function(curInput) {
   Event.observe(curInput, 'click', function() {
        alert('some click logic goes here');
    });
   Event.observe(curInput, 'change', function() {
        alert('some change logic goes here');
    });
});​

这篇关于Magento后端,捕获不同元素上的onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆