Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
35.1.Setup: For Dependent Select Fields{Adding the First Select Field}
We're going to tackle one of the most annoying things in Symfony's form system, and, I hope, make it as painless as possible... because the end result is pretty cool! Log in as admin2@thespacebar.com, password engage and then go to /admin/article. Click to create a new article. Here's the goal: on this form, I want to add two new drop-down select elements: a location drop-down - so you can choose where in the galaxy you are - and a second dropdown with more specific location options depending on what you chose for the location. For example, if you select "Near a star" for your location, the next drop-down would update to be a list of stars. Or, if you select "The Solar System", the next drop-down will be a list of planets. Adding the First Select Field This is called a "dependent form field", and, unfortunately, it's one of the trickier things to do with the form system - which is exactly why we're talking about it! Let's add the first new field. Find your terminal and run php bin/console make:entity Modify the Article entity and create a new field called location. Make it a string field with yes to nullable in the database: the location will be optional. Now run: php bin/console make:migration and open the Migrations/ directory to check out that new file. No surprises here, so let's go back and run it: php bin/console doctrine:migrations:migrate Perfect!
- Loading branch information