Closed archonic closed 6 years ago
Turns out I just needed to import and start RailsUJS as a module:
import Rails from 'rails-ujs';
Rails.start();
Now data-confirm-modal is working on objects with the data-confirm attribute, but I noticed that confirmModal() is still not a method on selected objects. This seems to just be a readme issue.
Ciao @archonic,
the NPM package is mostly untested, though the data-confirm-modal code is self-contained so it should work. Anyway, if you are not using rails-ujs
I am not sure it gives you any benefit from importing it.
I am puzzled by the fact that confirmModal()
is not available on jQuery objects. As you have the modal behaviour working, the data-confirm-modal source is being loaded and executed, and as part of initialisation the confirmModal()
method is added to jQuery.fn
, see here.
Are you sure that your $
is jQuery and not something else?
Good point - I wasn't loading jQuery right with webpacker. I needed window.$ = window.jQuery = require('jquery');
in addition to import 'jquery'
. Thanks!
Cool! Glad to hear it works :-) Thanks for the feedback.
I'm using the NPM package since I'm using webpacker. When the jQuery selector works and the dataConfirmModal object exists, I'm still getting
$(...).confirmModal is not a function
when calling$('#delete_link').confirmModal();
. I'm also loading rails-ujs though webpacker, although not including data-confirm-modal isn't giving me a browser confirm. Does this mean I have a rails-ujs loading issue? I would have thought data-confirm-modal would be a function regardless of the presence of rails-ujs.