ChoiceType Field (select Drop-downs, Radio Buttons & Checkboxes)
Có thể bạn quan tâm
choice_attr
type: array, callable, string or PropertyPath default: []
Use this to add additional HTML attributes to each choice. This can be an associative array where the keys match the choice keys and the values are the attributes for each choice, a callable or a property path (just like choice_label).
If an array, the keys of the choices array must be used as keys:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 use Symfony\Component\Form\Extension\Core\Type\ChoiceType; // ... $builder->add('fruits', ChoiceType::class, [ 'choices' => [ 'Apple' => 1, 'Banana' => 2, 'Durian' => 3, ], 'choice_attr' => [ 'Apple' => ['data-color' => 'Red'], 'Banana' => ['data-color' => 'Yellow'], 'Durian' => ['data-color' => 'Green'], ], ]); // or use a callable $builder->add('attending', ChoiceType::class, [ 'choices' => [ 'Yes' => true, 'No' => false, 'Maybe' => null, ], 'choice_attr' => function ($choice, string $key, mixed $value) { // adds a class like attending_yes, attending_no, etc return ['class' => 'attending_'.strtolower($key)]; }, ]);Tip
When defining a custom type, you should use the ChoiceList class helper:
1 2 3 4 5 6 7 8 9 use App\Entity\Category; use Symfony\Component\Form\ChoiceList\ChoiceList; // ... $builder->add('choices', ChoiceType::class, [ 'choice_attr' => ChoiceList::attr($this, function (?Category $category): array { return $category ? ['data-uuid' => $category->getUuid()] : []; }), ]);See the "choice_loader" option documentation.
Từ khóa » Choix Html
-
The HTML Select Element - HTML: HyperText Markup Language
-
-
HTML Select Form Attribute - W3Schools
-
HTML Select Multiple Attribute - W3Schools
-
: Zone De Saisie Avec Une Liste Déroulante - ULB">: Zone De Saisie Avec Une Liste Déroulante - ULB
-
HTML/XHTML / Formulaires / Listes De Choix, Cases D'option Et ...
-
Html -Les Formulaires - Liste Déroulante
-
HTTP/1.1: Status Code Definitions
-
Choosing The Right Estimator — Scikit-learn 1.1.2 Documentation
-
HTML5 Et CSS3 - Les Cases à Cocher à Choix Multiple | Editions ENI
-
Choix Multiples Avec L'élément HTML Select - Guyom Design
-
“Best Real Croissants” Review Of Le Bon Choix - Brisbane - TripAdvisor
-
Domaine Pas De Choix : Government Intervention In The Champagne ...