Chapters
40 Chapters
|
4:19:16
|
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!
20.
Custom Field JavaScript
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.
This tutorial is built on Symfony 6 but works great on Symfony 7!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2.0",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99.4
"doctrine/doctrine-bundle": "^2.1", // 2.5.5
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.2.1
"doctrine/orm": "^2.7", // 2.10.4
"easycorp/easyadmin-bundle": "^4.0", // v4.0.2
"handcraftedinthealps/goodby-csv": "^1.4", // 1.4.0
"knplabs/knp-markdown-bundle": "dev-symfony6", // dev-symfony6
"knplabs/knp-time-bundle": "^1.11", // 1.17.0
"sensio/framework-extra-bundle": "^6.0", // v6.2.5
"stof/doctrine-extensions-bundle": "^1.4", // v1.7.0
"symfony/asset": "6.0.*", // v6.0.1
"symfony/console": "6.0.*", // v6.0.2
"symfony/dotenv": "6.0.*", // v6.0.2
"symfony/flex": "^2.0.0", // v2.4.5
"symfony/framework-bundle": "6.0.*", // v6.0.2
"symfony/mime": "6.0.*", // v6.0.2
"symfony/monolog-bundle": "^3.0", // v3.7.1
"symfony/runtime": "6.0.*", // v6.0.0
"symfony/security-bundle": "6.0.*", // v6.0.2
"symfony/stopwatch": "6.0.*", // v6.0.0
"symfony/twig-bundle": "6.0.*", // v6.0.1
"symfony/ux-chartjs": "^2.0", // v2.0.1
"symfony/webpack-encore-bundle": "^1.7", // v1.13.2
"symfony/yaml": "6.0.*", // v6.0.2
"twig/extra-bundle": "^2.12|^3.0", // v3.3.7
"twig/twig": "^2.12|^3.0" // v3.3.7
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.4.1
"symfony/debug-bundle": "6.0.*", // v6.0.2
"symfony/maker-bundle": "^1.15", // v1.36.4
"symfony/var-dumper": "6.0.*", // v6.0.2
"symfony/web-profiler-bundle": "6.0.*", // v6.0.2
"zenstruck/foundry": "^1.1" // v1.16.0
}
}
10 Comments
This Stimulus controller will affect all the views. Is there a way to load it only in the edit and new views?
Hey @ahmedbhs
Yes, you can activate lazy loading on your Stimulus controllers by adding this annotation on top of the controller's definition
It's a Symfony UX feature, so you need to install that component on your app
Cheers!
Hi, does anyone knows why I cannot get bootstrap features to work?
Things like <a href="https://getbootstrap.com/docs/4.0/components/carousel/"> carousel</a> (no sliding) <a href="https://getbootstrap.com/docs/4.0/components/dropdowns/">dropdown</a> (no dropdown)
don't work in the base.html.twig ?
isn't the
{{ encore_entry_script_tags('app') }}in that file supposed to add bootstrapt link since app.js already import bootstrap ?Hey grenouille!
> isn't the {{ encore_entry_script_tags('app') }} in that file supposed to add bootstrapt link since app.js already import bootstrap ?
In theory, yes. But EasyAdmin also has its own Bootstrap JavaScript. What do you want to accomplish? And what does your app.js look like exactly?
Cheers!
Hello,
I noticed an issue that occurs when my javascript assets require bootstrap. For example, if I import 'bootstrap' (Twitter Bootstrap, not the stimulus bootstrap file) in 'admin.js', then the dropdown actions (such as the avatar in the top right, or the 3 dots at the end of the row on the index page) stop working.
I made sure that my project required the exact same version of Bootstrap as EasyAdmin. Could anyone shine some light onto what the issue could be?
thanks,
Colin
Hey Colin,
I can't say for sure... but I would like to know why do you include bootstrap to your admin? Well, first of all, EasyAdmin already has bootstrap included, it's based on the latest bootstrap. So, you probably don't want to include your own one, even if you're including the same version, because it will cause some conflicts. Well, maybe not conflicts, but duplications for sure, as both CSS files will apply same rules twice.
But, if you curious to know the reason it breaks sometimes - then, in theory, it's because that EasyAdmin is based on bootstrap but also slightly modifies it. And so, the workflow when you include your own bootstrap is the next probably:
1. EasyAdmin includes bootstrap
2. EasyAdmin slightly modifies bootstrap for its needs
3. You include the bootstrap again, that overrides some rules that were overwritten by EasyAdmin
Well, sometimes like this, I can't think of anything else. Or, it might be so that you're including a bit different version of bootstrap that causes those issues. But in theory, if EA already has bootstrap (and it does have it) - you better don't include it again and just reuse the bootstrap EasyAdmin uses behind the scene.
I hope this helps.
Cheers!
Just for future reference, EA includes a global bootstrap var that can be used: https://github.com/EasyCorp...
There is no need to import bootstrap
Hey Edin,
Nice, thanks for sharing this!
Cheers!
Hey Victor,
I agree, there isn't a reason to include bootstrap again. I just noticed that the dropdowns stopped working after I showed another developer how to include custom webpack entries, and narrowed the cause of the error to importing bootstrap in our custom javascript we were adding to EasyAdmin.
For instance in our custom javascript we had:
which caused the error.
Probably from the beginning this should have been:
which works fine.
The theory of the EasyAdmin bootstrap modifications makes sense, I didn't think to check that out, so thank you for pointing that out.
Thanks for the help,
Colin
Hey Colin,
Ah, I see! So, it's good you thought about why it happened 👍. Yeah, not sure about how to import that Modal correctly, probably Bootstrap docs should cover, just look closer to the version of Bootstrap, they have a bit different docs for different version of it. But if it works with "bootstrap/js/dist/modal" path - great, thanks for sharing it!
Yeah, EasyAdmin have some tweaks to the bootstrap defaults... just to look less "bootstrappy" and be more unique, you know.
Anyway, I hope it helped!
Cheers!
"Houston: no signs of life"
Start the conversation!