Launching bootstrap modal from data-keybinding using rails mousetrap gem

121 Views Asked by At

I am wondering if anyone knows whether the mousetrap gem for creating keybindings has the ability to launch a bootstrap modal dialog.

As it stands, when I use 'link_to' to launch a modal such as:

<%= 
   link_to "Insert", new_item_path, remote: true, 
        data: { toggle: 'modal', target: '#myModal' }
%>

this calls the new.js.erb file which populates the modal with the appropriate _form partial. Yet, when I add the mousetrap keybinding parameter as:

<%= 
   link_to "Insert", new_item_path, remote: true, 
        data: { toggle: 'modal', target: '#myModal', keybinding: 'I' }
%>

the result is no longer a modal generated from the new.js.erb which shows the form, but rather it seems that the controller picks this up as format.HTML and thus renders 'new.html.erb' which is not really used.

Any ideas on how to perform a keybinding to show the modal instead without doing it via .js?

0

There are 0 best solutions below