LoginSignup
7
4

More than 1 year has passed since last update.

Rails7 button_toでdata: { turbo: false }でも確認ダイアログを表示させる

Last updated at Posted at 2022-06-10

やりたいこと

削除ボタンに対して、Turboは無効化し、確認ダイアログは表示させたい。
しかし、 turbo_confirmを用いた実装ではTurboが無効化されているため、確認ダイアログの表示ができない。

参照

実装方針

JSを使って確認ダイアログを表示させます。

<%= button_to "削除する", reservation_path(reservation), method: :delete, data: { turbo: false }, form: { onSubmit: "return check()" } %>
function check(){
  if(window.confirm('本当に削除しますか?')){ 
    return true;
  }
  else{
    window.alert('キャンセルされました'); 
    return false; 
  }
}
7
4
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
7
4