Modal Twig Component
…done! The data-turbo-frame="modal"
would load that page into the modal.
But since we've done that before, let's try something different. Delete the href,
change this to a button, remove the data-turbo-frame attribute... and change
the yellow colors to…
Ajax Form Response Status Codes
…The 422 status code means "unprocessable entity". And it's a pretty standard
status code for validation errors. As a bonus, doing this on your forms will play
super nicely with Stimulus's sister technology Turbo. Oh, and by the way, in
Symfony 5.3…
Toast Notifications
…the bottom. Say
then
{{ include('_flashes.html.twig') }}:
The id="flash-container" isn't important yet, but it will be useful later when
we talk about
Turbo streams.
So let's see if this works! Hit "Save" and... there we…
Entity Class
…mixes in our system. So
let's create a new class called VinylMix. Then answer no for broadcasting
entity updates: that's an extra feature related to Symfony Turbo.
Ok, here's the important part: it asks which properties we want. We're going
to…
To use API Token Authentication or Not?
…form. And if you do want to get
fancy and submit your login for via Ajax, you can totally do that. In fact, if you
use Turbo, that happens automatically. But if you wanted to write some custom
JavaScript, it's still no problem. Just…
Smartly Updating Elements for all Users
…
That's... ya know... not what we want. But I can already see the problem: in
the turbo stream, we're sending the entire _reviews.html.twig template to
all users... which includes the reviews list... but also the flash message and
the form.
No…
Visually Highlighting new Items that Pop onto the Page
…how
about, streamed-item_controller.js. I'll paste in the normal structure, which
imports turbo, exports the controller and creates a connect() method.
Before we fill this in, go over to _review.html.twig and use this. I'll break this
onto multiple lines…
Form Improvements for Symfony 6
…error. And second, if you're
using Turbo, this is needed so that Turbo knows that your form validation failed.
You get that for free just by using the new shortcut method.
Next, Symfony comes with some nice and optional Docker integration for local
development…
Multiple Updates in one Stream
…
Well... that's almost disappointingly easy! Remember: we're inside of a
turbo-frame... so all we need to do is add a link in the frame that navigates
us to the review page... because the review page renders this frame
with a fresh form…
Frame-Powered Inline Editing
…Nothing magic yet. When we refresh, there's our link... a fantastically boring edit
link. Thanks to Turbo Drive, clicking it feels pretty good. And with a bit more work,
we could add a link back to the public show page. Heck, we could even…
Adding a "Read More" Ajax Frame
…see that an Ajax call failed!
So... we all know that - despite our awesomeness - errors happen. When you
work with turbo frames, these errors are harder to see since everything happens in
a background Ajax call. To see it, you can go to the network…
Stimulus: Writing Pro JavaScript
…application, right? A site where there are
zero full page refreshes. But to build one, don't we need to use a JavaScript
framework like React? No! We're going to transform our app into a single page
application in... about 3 minutes with Turbo.
Submitting a Form via GET
…also happens via Turbo, and form errors still work perfectly.
On the parts list, if you go to "Create new part" and try to send the empty
form... Yep, that's an AJAX request and we still see the expected validation
errors. Turbo makes our…
Upgrading to Symfony 6.4
…It's happy! In the main tab, run:
git status
Alongside the usual suspects, there's a new controller in controllers.json...
which came from an update to ux-turbo. We won't use it, but it's fine there.
In package.json, it added…
HTML dialog for Modals
…for example in _flashes.html.twig, is to
add a data-turbo-temporary attribute:
That tells Turbo to remove this element before it takes the snapshot.
Let's try adding this to our dialog so it's not in the snapshot. To see what
happens…
Symfony UX Packages
…done with day 8! A full week and day into LAST stack! Tomorrow, we're
going to crank it up to eleven and transform our app into a sleek, single-page
wonder with Turbo! Over the next 7 days... things wil start to get crazy.
x
682