Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap 5 and Vanilla JS #83

Open
badstorm opened this issue Feb 12, 2021 · 10 comments
Open

Bootstrap 5 and Vanilla JS #83

badstorm opened this issue Feb 12, 2021 · 10 comments

Comments

@badstorm
Copy link

badstorm commented Feb 12, 2021

Hi, has anyone already started converting this to Vanilla JS for support for the next Bootstrap 5?

@tagliala
Copy link
Member

Hi @badstorm,

nope, sorry.

I will not work on this anytime soon. I've did some experiments. As far as I can tell, without jQuery we need to rewrite stuff or depend on third party libraries.

Are you interested in contributing with a PR?

@badstorm
Copy link
Author

Hi @tagliala, since i need to implement a non jquery version in one of my project I can try to work on it. If you add a branch with your experiments I can take a look and try to work on it (in my free time)

@tagliala
Copy link
Member

If you add a branch with your experiments I can take a look and try to work on it (in my free time)

I've dropped everything except the code you can see in this comment: #80 (comment)

Anyway, I would like to perform the following steps for this gem:

  1. Add rollup.js to generate distributable files. Example
  2. Customize Rails.confirm
  3. When BS4 and @rails/ujs support has been improved (and fixed), add BS5 compatibility
  4. Cross-browser integration tests 😊
  5. Convert to vanilla JS, but leave the ability to use jQuery, as Bootstrap 5 does.

I've also found this blog post. Code snippets are licensed under MIT

@tagliala
Copy link
Member

This is an experimental working version with Bootstrap 5 AND jQuery

https://github.com/diowa/ruby3-rails6-bootstrap-heroku/blob/experimental/data-confirm-modal-rails-confirm-bs5/app/javascript/src/data-confirm-modal.js

@jdsampayo
Copy link

In a project that is not using Webpack, added the solution of @tagliala in location vendor/assets/javascripts/data-confirm-modal.js and replaced:

import jQuery from 'jquery'
import Rails from '@rails/ujs'
import { onDOMContentLoaded } from 'bootstrap/js/src/util/index'

onDOMContentLoaded(() => {

for:

$( document ).on('turbolinks:load', function() {

and it worked.

@tagliala
Copy link
Member

Hi,

I think it's because

$( document ).on('turbolinks:load', function() {

is being triggered after onDOMContentLoaded, so Bootstrap had the chance to define modal inside jQuery

@ghost
Copy link

ghost commented Jun 16, 2021

I'm trying to rewrite your experiment version in ES6 with no jQuery support. I have a onRails project that use rails-ujs where we dropped support for jQuery.

But In ES6 modules are imported readonly and so I don't know how to extend the original Rails object (
in particular the Rails.confirm function).

Dose anyone have some suggestion about that? Thanks

@tagliala
Copy link
Member

@stormenergy91

can you share the error you are getting?

@ghost
Copy link

ghost commented Jun 16, 2021

This is my actual file structure:

import Rails  from '@rails/ujs'

export class DataConfirmModal
{
    constructor()
    {
        // ..

        Rails.confirm = function (message, el ) {

            // ...

            return true;
        }
    }
}

I get the error at line Rails.confirm = and the error is Cannot assign to 'confirm' because it is an import.

@tagliala
Copy link
Member

We should also get rid of Rails.confirm, there is an interesting gorails episode

https://gorails.com/episodes/custom-hotwire-turbo-confirm-modals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants