Dynamic forms in Hotwire

  Рет қаралды 6,371

Rapid Ruby

Rapid Ruby

Күн бұрын

In this video, I'll show you a neat trick to swap out form fields dynamically using Turbo Frames and a tiny bit of stimulus JS (only ~5 lines). This is something I've used on a few production projects and comes in handy on your Hotwire Rails apps.
You can follow along with the source code before this tutorial:
github.com/phawk/coinfusion/t...
And the finished code is here:
github.com/phawk/coinfusion/t...
Chapters
00:00 Intro
00:17 Example Scenario
01:23 Setting Up Fields
02:30 Turboframe Wrapper
03:50 Adding Navigation Controller
05:12 Controller Params
06:34 Testing Toggle Function
07:37 Conclusion
If you like this content, please consider subscribing to the channel.
---
Has this video helped you out? Consider buying me a coffee to say thanks and support future content like this, thanks!
app.payhere.co/rapid-ruby/buy...
You can also find more content like this, including premium courses and exclusive community and mentorship to help you level-up! Head over to rapidruby.com and use the code RRKZbin for a discount!

Пікірлер: 19
@repoles
@repoles Жыл бұрын
Oh my god! I didn't know that if you change dynamically the `src` of a turbo-frame it will make its magic to reload the content! Amazing technic!!! 👏
@SupeRails
@SupeRails 2 жыл бұрын
Very interesting idea with a stimulus controller and redirecting onsubmit within a turbo_frame with some params.... also, nice to see enums to strings ( individual: "individual" )
@fjdeveloper
@fjdeveloper 2 жыл бұрын
Amazing. Thanks for sharing
@clementcoquille4153
@clementcoquille4153 Ай бұрын
Nice one ! Couldnt we improve it futher more by sending a turbo_stream :replace instead of re-sending the whole page ? Clicking radio buttons reload the whole page, when it could only send the desired tags
@ledockol
@ledockol 2 жыл бұрын
Great! Thanks!
@EnjoytheMents
@EnjoytheMents 2 жыл бұрын
Nice explanation. Thanks. What theme u use for vscode?
@rapid-ruby
@rapid-ruby 2 жыл бұрын
Thanks! It’s the Electron Color Theme, you can find the package link here: marketplace.visualstudio.com/items?itemName=kuscamara.electron
@tolaseadegbite1027
@tolaseadegbite1027 Ай бұрын
Hello, how do I implement the controller params part? I generated devise controllers but the content is different from yours.
@Ben-ni9bc
@Ben-ni9bc 8 ай бұрын
Thanks for yours videos. How can I do the same things with a select insteed a checkbox ?
@rapid-ruby
@rapid-ruby 8 ай бұрын
Thanks Ben! The same technique should work regardless of the form element being used!
@pging8328
@pging8328 9 ай бұрын
is it a crazy idea to use morphdom to submit the entire form to a controller action (with a new url / form action) - that way you can have truly dynamic forms, i.e. have validation happening when a field is blurred, or using dynamic forms as you have done - only the aspect that have changed need to be updated, morph dom takes care of that.
@monetiza
@monetiza Жыл бұрын
Dope
@pging8328
@pging8328 9 ай бұрын
Wait a minute: don't you need to submit the form everytime someone clicks on "company" or "individual"?
@ddd2283
@ddd2283 2 жыл бұрын
Why no souce code (((
@rapid-ruby
@rapid-ruby 2 жыл бұрын
Hi Dima, apologieis I forgot to put the links to the source code into the description. It should be in now, and you can see the final version here: github.com/phawk/coinfusion/tree/turbo_frames_2 Thanks!
@ddd2283
@ddd2283 2 жыл бұрын
@@rapid-ruby tons thanks!
@ddd2283
@ddd2283 2 жыл бұрын
@@rapid-ruby i think this repo is private ((( i got 404
@rapid-ruby
@rapid-ruby 2 жыл бұрын
My bad! I have just made it public now, thanks for letting me know!
@ddd2283
@ddd2283 2 жыл бұрын
@@rapid-ruby my mind was broken )))) i spend a lot of time before understanding become to me ))) ./bin/rails turbo:install && ./bin/rails stimulus:install needs after git clone :))) Now all works fine! Thank you a lot!
Flash messages with Hotwire
8:49
Rapid Ruby
Рет қаралды 3,3 М.
When someone reclines their seat ✈️
00:21
Adam W
Рет қаралды 21 МЛН
Эффект Карбонаро и бесконечное пиво
01:00
История одного вокалиста
Рет қаралды 6 МЛН
Чай будешь? #чайбудешь
00:14
ПАРОДИИ НА ИЗВЕСТНЫЕ ТРЕКИ
Рет қаралды 2,6 МЛН
Ruby on Rails #80 Dynamic Forms with Turbo (not JS approach)
18:23
Stimulus Nested Forms | Ruby on Rails 7 Tutorial
14:37
Deanin
Рет қаралды 7 М.
Turbo Frame Modals (Popups) | Ruby On Rails 7 Tutorial
12:49
Turbo Frames vs. Turbo Streams
8:25
Mix & Go
Рет қаралды 16 М.
What is Hotwire?
6:55
The Pragmatic Studio
Рет қаралды 10 М.
ViewComponents in the Real World - Joel Hawksley
34:17
Ruby Central
Рет қаралды 7 М.
Не обзор DJI Osmo Pocket 3 Creator Combo
1:00
superfirsthero
Рет қаралды 1,3 МЛН
iPhone 15 Pro vs Samsung s24🤣 #shorts
0:10
Tech Tonics
Рет қаралды 11 МЛН
С Какой Высоты Разобьётся NOKIA3310 ?!😳
0:43