diff --git a/README.md b/README.md index 5514a60..49b4945 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,47 @@ Available themes: ### Easyadmin -TBD +Create webpack entry: + +```javascript +// webpack.config.js +.addEntry('stimulus', './assets/stimulus.js') +``` + +Then create that javascript file: + +```javascript +// assets/stimulus.js + +// start the Stimulus application +import './bootstrap'; +``` + +Use the new collection type in the easyadmin controller: + +```php +namespace App\Controller\EasyAdmin; + +use Tienvx\UX\CollectionJs\Form\CollectionJsType; + +class FormFieldReferenceController extends AbstractCrudController +{ + public function configureCrud(Crud $crud): Crud + { + return $crud + // ... + ->setFormThemes(['@EasyAdmin/crud/form_theme.html.twig', '@CollectionJs/bootstrap_5_layout.html.twig']); + } + + public function configureFields(string $pageName): iterable + { + yield CollectionField::new('collectionSimple', 'Collection Field (simple)') + ->setFormType(CollectionJsType::class) + ->setFormTypeOption('entry_type', CollectionSimpleType::class) + ->addWebpackEncoreEntries('stimulus'); + } +} +``` ## Contributing Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. diff --git a/src/Resources/views/bootstrap_3_layout.html.twig b/src/Resources/views/bootstrap_3_layout.html.twig index 9da4da8..43292cc 100644 --- a/src/Resources/views/bootstrap_3_layout.html.twig +++ b/src/Resources/views/bootstrap_3_layout.html.twig @@ -19,7 +19,7 @@
- {{ form_widget(form) }} + {{ block('collection_js_accordion_item_body') }}
diff --git a/src/Resources/views/bootstrap_4_layout.html.twig b/src/Resources/views/bootstrap_4_layout.html.twig index 46d85eb..d2df13a 100644 --- a/src/Resources/views/bootstrap_4_layout.html.twig +++ b/src/Resources/views/bootstrap_4_layout.html.twig @@ -19,7 +19,7 @@
- {{ form_widget(form) }} + {{ block('collection_js_accordion_item_body') }}
diff --git a/src/Resources/views/bootstrap_5_layout.html.twig b/src/Resources/views/bootstrap_5_layout.html.twig index edc98ef..c3f1d4b 100644 --- a/src/Resources/views/bootstrap_5_layout.html.twig +++ b/src/Resources/views/bootstrap_5_layout.html.twig @@ -19,7 +19,7 @@
- {{ form_widget(form) }} + {{ block('collection_js_accordion_item_body') }}
diff --git a/src/Resources/views/bootstrap_base_layout.html.twig b/src/Resources/views/bootstrap_base_layout.html.twig index fd320ad..b463a75 100644 --- a/src/Resources/views/bootstrap_base_layout.html.twig +++ b/src/Resources/views/bootstrap_base_layout.html.twig @@ -19,19 +19,19 @@ {% if form_parent(form).vars.allow_move_up %} {% endif %} {% if form_parent(form).vars.allow_move_down %} {% endif %} {% if form_parent(form).vars.allow_delete %} {% endif %} {% endapply %} diff --git a/src/Resources/views/form_div_layout.html.twig b/src/Resources/views/form_div_layout.html.twig index f145dad..e4b5555 100644 --- a/src/Resources/views/form_div_layout.html.twig +++ b/src/Resources/views/form_div_layout.html.twig @@ -81,6 +81,8 @@ {% endblock collection_js_actions %} -{% block collection_entry_widget %} - {{ form_widget(form) }} -{% endblock collection_entry_widget %} +{% block collection_js_accordion_item_body %} + {% for child in form|filter(child => not child.rendered) %} + {{- form_row(child) -}} + {% endfor %} +{% endblock collection_js_accordion_item_body %}