0

我想在文本元素上添加事件

    $barcodeFieldset = $form->addFieldset('form_barcode', array('legend' => Mage::helper('adminhtml')->__('Barcode Information')));

    $barcodeFieldset->addField('barcode', 'submit', array(
        'label' => Mage::helper('adminhtml')->__('Barcode'),
        'name' => 'barcode',
        'onKeyDown' => "alert('x')",
        'required' => true,
        'note' => 'If You want to scan barcode, focus to this textfield.',
        $this->_isReadonly() => $this->_isReadonly(),
    ));

onKeyDown 不起作用。如何使它起作用?

4

2 回答 2

0

出于某种原因,Magento 不允许这样做。以下是您可以在提交元素上指定的属性:'type', 'title', 'class', 'style', 'onclick', 'onchange', 'disabled', 'readonly', 'tabindex'. 这些来自Varien_Data_Form_Element_Abstract::getHtmlAttributes().
唯一允许 onkeydown(小写)的字段类型是link字段 ( Varien_Data_Form_Element_Link)。

于 2013-10-01T10:03:35.173 回答
0

这是我的想法。

    $barcodeFieldset = $form->addFieldset('form_barcode', array('legend' => Mage::helper('adminhtml')->__('Barcode Information')));

    $barcodeFieldset->addField('barcode', 'password', array(
        'label' => Mage::helper('adminhtml')->__('Barcode'),
        'name' => 'barcode',
        'after_element_html' =>
                "<script type='text/javascript'>" .
                "$('barcode').setAttribute('onKeyDown', 'if(event.keyCode == 13){editForm.submit($(" . "edit_form" . ").action)};');"
                . "</script>",
        'required' => true,
        'note' => 'If You want to scan barcode, focus to this textfield.',
        $this->_isReadonly() => $this->_isReadonly(),
    ));
于 2013-10-02T01:22:03.860 回答