@@ -448,7 +448,7 @@ By default, the user can't change the *properties* of an object ``LiveProp``
448
448
public Post $post;
449
449
450
450
#[LiveProp(writable: ['allow_markdown'])]
451
- public array $options = ['allow_markdown' => true, 'allow_html' => false]
451
+ public array $options = ['allow_markdown' => true, 'allow_html' => false];
452
452
}
453
453
454
454
Now ``post.title ``, ``post.content `` or ``options.allow_markdown `` can be used like
@@ -475,11 +475,17 @@ Any other properties on the object (or keys on the array) will be read-only.
475
475
For arrays, you can set ``writable: true `` to allow *any * key in the array to be
476
476
changed, added or removed::
477
477
478
- #[LiveProp(writable: true)]
479
- public array $options = ['allow_markdown' => true, 'allow_html' => false];
478
+ #[AsLiveComponent('edit_post')]
479
+ class EditPostComponent
480
+ {
481
+ // ...
480
482
481
- #[LiveProp(writable: true)]
482
- public array $todoItems = ['Train tiger', 'Feed tiger', 'Pet tiger'];
483
+ #[LiveProp(writable: true)]
484
+ public array $options = ['allow_markdown' => true, 'allow_html' => false];
485
+
486
+ #[LiveProp(writable: true)]
487
+ public array $todoItems = ['Train tiger', 'Feed tiger', 'Pet tiger'];
488
+ }
483
489
484
490
.. note ::
485
491
@@ -495,11 +501,15 @@ Checkboxes, Select Elements Radios & Arrays
495
501
496
502
Checkboxes can be used to set a boolean or an array of strings::
497
503
498
- #[LiveProp(writable: true)]
499
- public bool $agreeToTerms = false;
504
+ #[AsLiveComponent('edit_post')]
505
+ class EditPostComponent
506
+ {
507
+ #[LiveProp(writable: true)]
508
+ public bool $agreeToTerms = false;
500
509
501
- #[LiveProp(writable: true)]
502
- public array $foods = ['pizza', 'tacos'];
510
+ #[LiveProp(writable: true)]
511
+ public array $foods = ['pizza', 'tacos'];
512
+ }
503
513
504
514
In the template, setting a ``value `` attribute on the checkbox will set that
505
515
value on checked. If no ``value `` is set, the checkbox will set a boolean value:
@@ -515,11 +525,17 @@ value on checked. If no ``value`` is set, the checkbox will set a boolean value:
515
525
``select `` and ``radio `` elements are a bit easier: use these to either set a
516
526
single value or an array of values::
517
527
518
- #[LiveProp(writable: true)]
519
- public string $meal = 'lunch';
528
+ #[AsLiveComponent('edit_post')]
529
+ class EditPostComponent
530
+ {
531
+ // ...
532
+
533
+ #[LiveProp(writable: true)]
534
+ public string $meal = 'lunch';
520
535
521
- #[LiveProp(writable: true)]
522
- public array $foods = ['pizza', 'tacos'];
536
+ #[LiveProp(writable: true)]
537
+ public array $foods = ['pizza', 'tacos'];
538
+ }
523
539
524
540
.. code-block :: html+twig
525
541
@@ -549,8 +565,14 @@ the user to switch the *entity* to another? For example:
549
565
550
566
To make the ``post `` property itself writable, use ``writable: true ``::
551
567
552
- #[LiveProp(writable: true)]
553
- public Post $post;
568
+ use App\Entity\Post;
569
+
570
+ #[AsLiveComponent('edit_post')]
571
+ class EditPostComponent
572
+ {
573
+ #[LiveProp(writable: true)]
574
+ public Post $post;
575
+ }
554
576
555
577
.. caution ::
556
578
@@ -561,8 +583,14 @@ To make the ``post`` property itself writable, use ``writable: true``::
561
583
If you want the user to be able to change the ``Post `` *and * certain
562
584
properties, use the special ``LiveProp::IDENTITY `` constant::
563
585
564
- #[LiveProp(writable: [LiveProp::IDENTITY, 'title', 'content'])]
565
- public Post $post;
586
+ use App\Entity\Post;
587
+
588
+ #[AsLiveComponent('edit_post')]
589
+ class EditPostComponent
590
+ {
591
+ #[LiveProp(writable: [LiveProp::IDENTITY, 'title', 'content'])]
592
+ public Post $post;
593
+ }
566
594
567
595
Note that being able to change the "identity" of an object is something
568
596
that works only for objects that are dehydrated to a scalar value (like
@@ -578,9 +606,15 @@ when they are sent back to the backend.
578
606
If needed, you can control the normalization or denormalization context using
579
607
the ``Context `` attribute from Symfony's serializer::
580
608
581
- #[LiveProp]
582
- #[Context(groups: ['my_group'])]
583
- public Post $post;
609
+ use App\Entity\Post;
610
+
611
+ #[AsLiveComponent('edit_post')]
612
+ class EditPostComponent
613
+ {
614
+ #[LiveProp]
615
+ #[Context(groups: ['my_group'])]
616
+ public Post $post;
617
+ }
584
618
585
619
.. note ::
586
620
@@ -1641,17 +1675,19 @@ Here are some examples of these techniques.
1641
1675
If you only want to customize some attributes, the simplest to use the options in the form type::
1642
1676
1643
1677
// ...
1644
- ->add('comments', LiveCollectionType::class, [
1645
- 'entry_type' => CommentFormType::class,
1646
- 'label' => false,
1647
- 'button_delete_options' => [
1648
- 'label' => 'X',
1649
- 'attr' => [
1650
- 'class' => 'btn btn-outline-danger',
1651
- ],
1652
- ]
1653
- ])
1654
- // ...
1678
+ $builder
1679
+ // ...
1680
+ ->add('comments', LiveCollectionType::class, [
1681
+ 'entry_type' => CommentFormType::class,
1682
+ 'label' => false,
1683
+ 'button_delete_options' => [
1684
+ 'label' => 'X',
1685
+ 'attr' => [
1686
+ 'class' => 'btn btn-outline-danger',
1687
+ ],
1688
+ ]
1689
+ ])
1690
+ ;
1655
1691
1656
1692
Inline rendering:
1657
1693
@@ -2011,7 +2047,7 @@ There are three ways to emit an event:
2011
2047
2012
2048
class MyComponent
2013
2049
{
2014
- use ComponentEmitsTrait
2050
+ use ComponentEmitsTrait;
2015
2051
2016
2052
#[LiveAction]
2017
2053
public function saveProduct()
0 commit comments