2013-10-01 20 views
0

我想文本元素上瓦瑞恩數據表單元素添加onKeyDown事件在Magento

$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不起作用上添加事件。如何使它工作?

回答

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(), 
    )); 
0

由於某種原因,Magento不允許這樣做。以下是您可以在提交元素上指定的屬性:'type', 'title', 'class', 'style', 'onclick', 'onchange', 'disabled', 'readonly', 'tabindex'。這些來自Varien_Data_Form_Element_Abstract::getHtmlAttributes()
允許onkeydown(使用小寫)的唯一字段類型是link字段(Varien_Data_Form_Element_Link)。

+2

哎!有沒有辦法欺騙它?因爲條形碼掃描器的行爲是填充文本和ENTER。我必須用onKeyDown觸發它。 T_T –

+2

@JosuaMarcelChrisano您可以嘗試使用'link'類型字段,或創建自己的接受onkeydown屬性的字段 – Marius

相關問題