我想在文本元素上添加事件
$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不起作用。如何使其有效?
答案 0 :(得分:1)
这是我的想法。
$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(),
));
答案 1 :(得分:0)
出于某种原因,Magento不允许这样做。以下是您可以在提交元素上指定的属性:'type', 'title', 'class', 'style', 'onclick', 'onchange', 'disabled', 'readonly', 'tabindex'
。这些来自Varien_Data_Form_Element_Abstract::getHtmlAttributes()
允许onkeydown(以小写字母表示)的唯一字段类型是link
字段(Varien_Data_Form_Element_Link
)。