1
0

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 3 years have passed since last update.

【Salesforce】apex:commandButtonタグではなくbuttonタグを使用して入力項目にフォーカス時、Enterキーを押下した際にsubmitしないようにしたい

Last updated at Posted at 2021-01-27

実現方法

test.page
<!-- 修正前 ※入力項目にフォーカス時、Enterキーを押下でSubmitしてしまう -->
<apex:commandButton value="ボタン" action="{!method}" styleClass="slds-button slds-button_neutral" />

<!-- HTML読み込み時、typeがsubmitになるため -->
<input type="submit" value="ボタン" class="btn slds-button slds-button_neutral">

<!-- 修正後 -->

<!-- buttonなのでEnterキーで起動しない -->
<button type="button" class="slds-button slds-button_neutral" onclick="method();">
    ボタン名
</button>
<!-- onclickからApexを起動 -->
<apex:actionFunction name="method" action="{!method}"/>

※apex:commandButtonのtype(html-type)をbuttonに上書きしようとしたら「apex:commandButtonの属性「type」は上書きできません」とエラーになりました。

参考リンク

その他の方法
Enterキーの無効化

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?