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