0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Salesforce】バーコードスキャナーで読み込んだバーコードから検索したい

Posted at

問題

バーコードスキャナーで読み込んだバーコードから検索したい

解決策

test.page

<!-- ここに読み込んだバーコードを入れる -->
<!-- onkeypressの場合、「ひらがな」入力だと動かない -->
<apex:inputText value="{!barcode}" onkeydown="return handlerEnterKeyPress(event, '{!$Component.検索ボタンのID}')" />

<!-- 検索ボタン -->
<apex:commandButton id="検索ボタンのID" action="{!Apexの処理}" value="検索"/>

test.js

function handlerEnterKeyPress(e, buttonId){
    
    // e.codeに分別できる値が入っている
    // キービードからEnterを押下した場合は"Enter"
    // 読み込み後、Enter起動のバーコードスキャナーが読み込んだ場合は"NumpadEnter"
    if(e.code == "Enter" || e.code == "NumpadEnter"){
        // 検索ボタンを押下して、バーコードからレコードを取得する
        document.getElementById(buttonId).click();
        return false;
    }
    // 他の入力は処理を行わない
    // 例えば、KeyAやKeyWなど
    return true;
}

参考リンク

onkeydown属性 onkeypress属性 onkeyup属性

押したキーのキーコードを取得

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?