Chapters
32 Chapters
|
4:16:27
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "4.x-dev", // 4.x-dev
"doctrine/doctrine-bundle": "^2.10", // 2.12.x-dev
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.4.x-dev
"doctrine/orm": "^2.16", // 2.18.x-dev
"knplabs/knp-time-bundle": "dev-main", // dev-main
"pagerfanta/doctrine-orm-adapter": "4.x-dev", // 4.x-dev
"pagerfanta/twig": "4.x-dev", // 4.x-dev
"symfony/asset": "6.4.*", // 6.4.x-dev
"symfony/asset-mapper": "6.4.*", // 6.4.x-dev
"symfony/console": "6.4.x-dev", // 6.4.x-dev
"symfony/dotenv": "6.4.x-dev", // 6.4.x-dev
"symfony/flex": "^2", // 2.x-dev
"symfony/form": "6.4.x-dev", // 6.4.x-dev
"symfony/framework-bundle": "6.4.x-dev", // 6.4.x-dev
"symfony/monolog-bundle": "^3.0", // dev-master
"symfony/runtime": "6.4.x-dev", // 6.4.x-dev
"symfony/security-csrf": "6.4.x-dev", // 6.4.x-dev
"symfony/stimulus-bundle": "2.x-dev", // 2.x-dev
"symfony/twig-bundle": "6.4.x-dev", // 6.4.x-dev
"symfony/ux-autocomplete": "2.x-dev", // 2.x-dev
"symfony/ux-live-component": "2.x-dev", // 2.x-dev
"symfony/ux-turbo": "2.x-dev", // 2.x-dev
"symfony/ux-twig-component": "2.x-dev", // 2.x-dev
"symfony/validator": "6.4.x-dev", // 6.4.x-dev
"symfony/web-link": "6.4.*", // 6.4.x-dev
"symfony/yaml": "6.4.x-dev", // 6.4.x-dev
"symfonycasts/dynamic-forms": "dev-main", // dev-main
"symfonycasts/tailwind-bundle": "dev-main", // dev-main
"tales-from-a-dev/flowbite-bundle": "dev-main", // dev-main
"twig/extra-bundle": "^2.12|^3.0", // 3.x-dev
"twig/twig": "^2.12|^3.0" // 3.x-dev
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.6.x-dev
"phpunit/phpunit": "^9.5", // 9.6.x-dev
"symfony/browser-kit": "6.4.*", // 6.4.x-dev
"symfony/css-selector": "6.4.*", // 6.4.x-dev
"symfony/debug-bundle": "6.4.x-dev", // 6.4.x-dev
"symfony/maker-bundle": "^1.51", // dev-main
"symfony/panther": "^2.1", // v2.1.1
"symfony/phpunit-bridge": "7.1.x-dev", // 7.1.x-dev
"symfony/stopwatch": "6.4.x-dev", // 6.4.x-dev
"symfony/web-profiler-bundle": "6.4.x-dev", // 6.4.x-dev
"zenstruck/browser": "1.x-dev", // 1.x-dev
"zenstruck/foundry": "^1.36" // 1.x-dev
}
}
What JavaScript libraries does this tutorial use?
// importmap.php
return [
'app' => [
'path' => './assets/app.js',
'entrypoint' => true,
],
'js-confetti' => [
'version' => '0.11.0',
],
'@hotwired/stimulus' => [
'version' => '3.2.2',
],
'@symfony/stimulus-bundle' => [
'path' => './vendor/symfony/stimulus-bundle/assets/dist/loader.js',
],
'tom-select' => [
'version' => '2.3.1',
],
'tom-select/dist/css/tom-select.default.css' => [
'version' => '2.3.1',
'type' => 'css',
],
'@hotwired/turbo' => [
'version' => '7.3.0',
],
'stimulus-popover' => [
'version' => '6.2.0',
],
'debounce' => [
'version' => '1.2.1',
],
'turbo-view-transitions' => [
'version' => '0.3.0',
],
'stimulus-use' => [
'version' => '0.52.1',
],
'flowbite' => [
'version' => '2.2.1',
],
'@popperjs/core' => [
'version' => '2.11.8',
],
'flowbite-datepicker' => [
'version' => '1.2.6',
],
];
12 Comments
Hello guys, thanks for the fabulous tutorials :)
I get the following error message in the console when opening the modal
Error: Missing target element "loadingContent" for "modal" controllerWhat is missing here? I also see that comes in your finished example as well. Can I ignore this?
Cheers!
Hey @creativx007
That's a little mistake coming from the course code (I'm going to fix it soon). For the moment, replace
loadingTemplatewithloadingContentintemplates/components/Modal.html.twigat line 37Cheers!
hey, thank you very much. That works.
Can I ask another question? I have also installed Flowbite for the design blocks. I only create the modals using the dialog element. But now I always get the following error in the console every time I call it:
Modal with id dialog does not exist. Are you sure that the data-modal-target attribute points to the correct modal id?Modal with id dynamicContent does not exist. Are you sure that the data-modal-target attribute points to the correct modal id?<br />Modal with id loadingContent does not exist. Are you sure that the data-modal-target attribute points to the correct modal id?How can I prevent this? Thanks and cheers :)
Great! I'm glad to know that it worked. About your other question, I'm not familiar with Flowbite, but unless those error messages are misleading, I think you need to double-check your modal id value, and also check that you're correctly setting the value of
data-modal-targetCheers!
Good morning :) Thank you very much, it is really a pleasure to work here - you get competent help and it works. I was able to fix the error with the ID dialog. I still can't solve the other two errors (Modal with id dynamicContent and Modal with id loadingContent).
In the base.html.twig template I have the following block:
Here I have the target dynamicContent - but I don't know what's happening here. The error complains that a modal with the ID dynamicContent doesn't exist. In the entire code, "dynamicContent" only appears in connection with data-modal-target. Do you have any ideas?
Cheers :)
I'm a bit confused about the error messages. It says that the "Modal with id dynamicContent" does not exist. So, it makes me think that you're creating 3 modal elements, but you should have only one. Please, double check that you're rendering the Modal component only once.
Now, the modal controller requires 3 target elements, dialog, dynamicContent, and loadingTemplate. Double-check that these 3 elements are set up correctly. You can check this code block or download the course code and look at the
finishdirectoryhttps://symfonycasts.com/screencast/last-stack/modal-component#codeblock-54eed16182
I hope it helps!
Hi guys,
I've come accross the comments, and I can say that I've got the same issue here.
3 same errors saying that the
data-modal-targetare not set, but it is...The modal works just fine, but still got the errors on page loading and after every action
Hi everyone !
Thanks again for that great tutorial !
I need to load an
<turbo-frame>modal (exactly like you do) but triggered from an stimulus controller (action).To do that I tried by putting an empty a tag in my html like
<a href="my_url" id="myIdLinkToLoadTurboFrame" data-turbo-frame="turbo_frame_id"></a>.And in my stimulus controller I do
this.element.querySelector('#myIdLinkToLoadTurboFrame').click();Work fine with Firefox, but doesn't work at all with Chrome and Safari.
Is it possible to trigger the same action of clicking the data-turbo-frame link but from an stimulus controller ?
Cheers!
Hey @ThierryGTH!
Really glad you enjoyed it!
Here's how I would probably handle this:
A) Pass the url -
my_url- into your Stimulus controller as a value so you have access to the URLB) Instead of trying to click the link, find the frame and set its
src:That should be all you need. The frame will see that the
srcjust changed and start doing its thing. In fact, I think when you havedata-turbo-frame="turbo_frame_id", all that does internally is take thehrefand put it onto thesrcof theturbo-frame. Then the frame handles things from there.Cheers!
Thank you very much !
That's work perfectly and it's much prettier setting src than virtually clicking a tag.
The issue with Chrome and Safari was just because I was using
data-action=click->inside an select option tag :<select><option data-action="click->myController#myFunctionToClickVirtualy>Add item</></select>The solution is to handle at the select level :
<select data-action="myController#myOnChangeFunctionToManageWhatToDoDependingValue"><option value="addItem">Add item</option></select>Cheers!
Hi!
Before, I was always using
stimulus_controller('modal')instead ofdata-controller="modal"in twig... something I learned from your other Stimulus tutorial and that I grew used to. I was using stimulus_target() and stimulus_action() the same way. This does not work inside the twig component's default attributes though.If i use this in Modal.html.twig
it complains: A hash key must be followed by a colon (:). Unexpected token "punctuation" of value "(" ("punctuation" expected with value ":").
Looking forward to finishing this great course!
Hey @escobarcampos!
Yea, I created these helpers and get used to them... then recently got accustomed to the attribute names. Now those feel better to me. But, both are fine!
You can do this - here's the reference in general about this (there's a note in this section) - https://symfony.com/bundles/ux-twig-component/current/index.html#component-attributes - I think you could combine them in this way, but I could be totally borking the syntax ðŸ«
The
.defaults()functions accepts a "hash" (i.e. associative array) andstimulus_controller('modal')returns an iterable object. So, iirc, using...to spread that will work. But let me know. It's not super smooth, and it may even have some escaping differences... I can't quite remember. This definitely helped push me towards just using the attributes.Cheers!
"Houston: no signs of life"
Start the conversation!