Hotwire Modals with ZERO JAVASCRIPT

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ธ.ค. 2024

ความคิดเห็น • 36

  • @bennadel
    @bennadel ปีที่แล้ว +2

    Solid stuff. I've been looking through a bunch of modal tutorials in Hotwire and they all seem to use the Streams approach to handle the errors. It's be great if there was a non-Streams way (since it adds some complexity); but, this seems to be the approach that I keep finding. Part of why Streams adds complexity is that if someone were to navigate to the "Add/Edit" page directly via the URL, interacting with the form wouldn't require Streams to work properly - it's only needed in the modal context. Anyway, good stuff - I'm just thinking out load.

    • @rapid-ruby
      @rapid-ruby  ปีที่แล้ว +1

      Hey Ben that’s a great point! I kinda find in practise I’m not allowing the contents of a modal to be edited outside the context of the modal, but maybe that’s just being a lazy developer 😅

    • @bennadel
      @bennadel ปีที่แล้ว +1

      @@rapid-ruby I'm on like week-2 of learning Hotwire, so I'm just trying to find all the boundaries (where it does / does not overlap with traditional SPA mentality). In theory, I love the idea of things being _fully_ progressively enhanced; but, I'm also not entirely convinced that it's always worthwhile. At the end of the day, I'm just trying to build a good product - not necessarily make every UI accessible all the time. Anyway, I appreciate the conversation.

    • @SeanLazer
      @SeanLazer 7 หลายเดือนก่อน

      @@bennadeldid you ever find a solution you like for this? These types of nested UIs/routes are the things that tools like Remix or NextJS make quite simple. Being able to deep link into the modal feels pretty important to me in a lot of cases!

  • @Maverral
    @Maverral 2 ปีที่แล้ว +2

    The problem seems to be in reloading the whole page after submit the form. Notice that when you click "Update" you'll get "redirect_to show" in controller and it rerenders the whole page, not just the specific turbo frame. It would be nice if you have index page with some data (e.g. users), you can edit specific users within modal and then back to index without rerendering the whole page again (which means fetching again all users from database).

  • @crisnahine1570
    @crisnahine1570 2 ปีที่แล้ว

    It was really helpful Pete. Looking for more tutorial regarding rails hotwire. Thank you

  • @BraisonsCrece
    @BraisonsCrece 2 ปีที่แล้ว +1

    👏👏👏👏 thank's for sharing Pete! Very good content

  • @Andrew18animelive
    @Andrew18animelive 5 หลายเดือนก่อน

    Muchas gracias, justo hoy necesitaba esa solución, eres un pro.

  • @EnjoytheMents
    @EnjoytheMents 3 ปีที่แล้ว +1

    Best video on hotwire!! Ty so much!!!

  • @eetfunk
    @eetfunk 2 ปีที่แล้ว +1

    How do you recommend we implement the Cancel button? It's obviously easy with Stimulus, but was just wondering if you had another clever trick?

    • @rapid-ruby
      @rapid-ruby  2 ปีที่แล้ว +2

      Sorry for the late response on this one, I missed it coming through! To keep with the zero javascript, you can link the button to the "show" action. So if your modal was edit_post_path(@post) for instance, you can link the cancel button to post_path(@post), because on that URL, the turbo frame tag for the modal will be empty, and thus, it will close the modal for you.

  • @repoles
    @repoles 2 ปีที่แล้ว +1

    Thank you for sharing!

  • @johnquarto
    @johnquarto 2 ปีที่แล้ว +1

    can you comment how if you needed to pass along some data with the button click for the modal to use , how you'd do that? for example, the profile ID ?

    • @rapid-ruby
      @rapid-ruby  2 ปีที่แล้ว

      Hotwire works best with state on the server side, so you would just make the URL of the button contain all the info/id’s required. Hope that helps!

  • @yuanweizhou935
    @yuanweizhou935 ปีที่แล้ว

    hey i followed your steps but i could not click on the submit button in the turbo fram tag. I don't see any errors either. Do you have suggestions on how to solve that?

  • @prakashsanyasi5608
    @prakashsanyasi5608 2 ปีที่แล้ว

    It was really helpful.
    Thank you

  • @dailydaisydog
    @dailydaisydog 2 ปีที่แล้ว

    I'm getting "TypeError: Module specifier, 'application' does not start with "/", "./", or "../". Referenced from" when running my app on safari (v15). Do you also see this error by any chance?

    • @rapid-ruby
      @rapid-ruby  2 ปีที่แล้ว +1

      Does the code still run ok? I think that error is due to import maps with safari, but it doesn’t affect it running?

    • @dailydaisydog
      @dailydaisydog 2 ปีที่แล้ว +1

      Oh yeah, i thought my code wasn't working but it was just `dialog` tag not working on safari! HA!

    • @dailydaisydog
      @dailydaisydog 2 ปีที่แล้ว

      Thanks for the response :)

  • @sinestesiachannel1897
    @sinestesiachannel1897 3 ปีที่แล้ว

    You are really good , take care bro)

  • @johnquarto
    @johnquarto 2 ปีที่แล้ว +1

    I'm confused how you just dropped in the tailwindUI modal component but where did the JS come from? I drop the same code in my app and nothing happens once the modal is showing (for example, to make it disappear). There doesn't seem to be any Stimulus, or even any JS, in your "source code after" repo

    • @rapid-ruby
      @rapid-ruby  2 ปีที่แล้ว

      Hi John, the secret is in the title, “zero JavaScript”, there isn’t any other than the Hotwire library itself. Hope that helps!

    • @johnquarto
      @johnquarto 2 ปีที่แล้ว

      @@rapid-ruby but in the tailwindui site, for the examples of the modals it says "requires javascript" (for the modals and I guess a few others). My understanding is that their site uses Alpine for the JS. yet yours worked just by dropping it in ?

    • @johnquarto
      @johnquarto 2 ปีที่แล้ว

      p.s. thanks for this video in the first place. Yours is one of the only ones that shows that the thing that calls the modal needn't be inside the modal component.

    • @johnquarto
      @johnquarto 2 ปีที่แล้ว +1

      @@rapid-ruby I just realized, too, that you don't really have a "cancel" button for the modal (or sometimes with modals cancel will happen if one clicks outside the modal itself). . You're depending on the Form's submit or cancel to send you back somewhere else. Out of curiousity if you don't use the Form's buttons, how would you get out ("cancel") the modal ?

    • @rapid-ruby
      @rapid-ruby  2 ปีที่แล้ว

      @@johnquarto yeah so the tailwind site only shows alpine or react afaik. My video tutuorial is using Hotwire, so don’t need any additional JS

  • @vasiovasio
    @vasiovasio ปีที่แล้ว +1

    For next videos Increase the font size and the audio volume please.

    • @rapid-ruby
      @rapid-ruby  ปีที่แล้ว

      Hey @vasiovasio, thanks for the feedback, this is one of my first videos, hopefully the audio quality and volume are much better now, but you can let me know :)

  • @erdemtopal4107
    @erdemtopal4107 2 ปีที่แล้ว

    Is anyone try it with bootstrap? I couldn't make it with bootstrap

    • @rapid-ruby
      @rapid-ruby  2 ปีที่แล้ว +1

      Hey Erdem, bootstrap adds quite a bit of complications if you want to use their models and their JavaScript together with Hotwire. I’d advise just using their styling and don’t use any of the bootstrap JS, instead rely on stimulus and Hotwire for any front end/JS needs.

  • @mikopiko
    @mikopiko 2 ปีที่แล้ว +1

    Why did my comment get removed? I only said this was impressive how we are able to create truly interactive webbapps in Rails using zero Javascript.

    • @rapid-ruby
      @rapid-ruby  2 ปีที่แล้ว +1

      Hi John, I didn't removed your comment, not sure what has happened, but thanks anyway :)