Chapters
41 Chapters
|
4:45:40
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3
Subscribe to download the code!Compatible PHP versions: ^7.1.3
-
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!
32.
Tweak your Form based on the Underlying Data
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": "^7.1.3",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.10.2
"doctrine/doctrine-bundle": "^1.6.10", // 1.10.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.7.2
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.0
"knplabs/knp-paginator-bundle": "^2.7", // v2.8.0
"knplabs/knp-time-bundle": "^1.8", // 1.8.0
"nexylan/slack-bundle": "^2.0,<2.2.0", // v2.0.0
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.0
"sensio/framework-extra-bundle": "^5.1", // v5.2.1
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.1.6
"symfony/cache": "^3.3|^4.0", // v4.1.6
"symfony/console": "^4.0", // v4.1.6
"symfony/flex": "^1.0", // v1.21.6
"symfony/form": "^4.0", // v4.1.6
"symfony/framework-bundle": "^4.0", // v4.1.6
"symfony/property-access": "^3.3|^4.0", // v4.1.6
"symfony/property-info": "^3.3|^4.0", // v4.1.6
"symfony/security-bundle": "^4.0", // v4.1.6
"symfony/serializer": "^3.3|^4.0", // v4.1.6
"symfony/twig-bundle": "^4.0", // v4.1.6
"symfony/validator": "^4.0", // v4.1.6
"symfony/web-server-bundle": "^4.0", // v4.1.6
"symfony/yaml": "^4.0", // v4.1.6
"twig/extensions": "^1.5" // v1.5.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.0.2
"easycorp/easy-log-handler": "^1.0.2", // v1.0.7
"fzaninotto/faker": "^1.7", // v1.8.0
"symfony/debug-bundle": "^3.3|^4.0", // v4.1.6
"symfony/dotenv": "^4.0", // v4.1.6
"symfony/maker-bundle": "^1.0", // v1.8.0
"symfony/monolog-bundle": "^3.0", // v3.3.0
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.1.6
"symfony/stopwatch": "^3.3|^4.0", // v4.1.6
"symfony/var-dumper": "^3.3|^4.0", // v4.1.6
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.1.6
}
}
7 Comments
How does this work in symfony 6? I'm using easy admin and can't see data in options.
Hey Courtney-T,
It should be there, are you talking about Symfony form type or something else from the EA? Please, share more information on what you're doing so we could help.
Cheers!
Sure, I'm trying to have an EA form basically update in real time. I have a form where a user can write a sale. So, it would be effective to have fields like the subtotal and total sale amount update as a user is selecting items to put on the sale. I realize I probably need some ajax, but I'm not entirely sure where to plug that in. Or a custom JS controller. I think I'm not entirely sure what the best approach is. Here's how I have things set up so far and I'm hoping you can point me in the right direction.
This is the CRUD controller:
This is the custom type I created for the item selection field:
I'm working on other custom field types as I think I need those to translate the data across fields.
Hey @Courtney-T!
I just replied over on your other question about this. So, let me know of that helps :).
Btw, perhaps unrelated to the "updating in real time part", it looks like you have some dynamic fields in your custom form type (e.g. the
$formModifierstuff). In case it helps, there's a new bundle that makes "dynamic fields" a whole heck of a lot easier - https://github.com/SymfonyCasts/dynamic-formsCheers!
This is great! Now what I need to figure out is how to integrate this with easy admin. I know how to make custom form types for individual fields, but I'm having trouble finding how I can use $builder in the crud controller itself. I vaguely remember something about $createForm.
Hey @Courtney-T!
Ah of course, good point! Let's see.
There are a few methods you can override to get the raw FormBuilder - e.g. https://github.com/EasyCorp/EasyAdminBundle/blob/4.x/src/Controller/AbstractCrudController.php#L528-L531. This will already be pre-built with all of the fields from
configureFields(). Anyway, you can grab this, put it inside of theDynamicFormBuilderand then add your conditional fields. So, the weird part is that, any fields that are dynamic should not be added viaconfigureFields(), but instead should be added manually to theFormBuilderinstance inside the overridden method. I think that will work, but I'm not entirely sure!I hope this helps - if you try it, let me know one way or another if it works. I haven't tried the dynamic forms library with EasyAdmin yet.
Cheers!
Lots of Thanks !!! The kind of stuff you won't find on official docs :)
"Houston: no signs of life"
Start the conversation!