Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Automaticcollection Laravel Package

eltharin/automaticcollection

View on GitHub
Deep Wiki
Context7

Symfony AutomaticCollection Bundle

Latest Stable Version Total Downloads Latest Unstable Version License

Installation

  • Require the bundle with composer:
composer require eltharin/automaticcollection

You can use eltharin/twigfilesgetter for load unique Js : https://github.com/eltharin/TwigFilesGetter

In this case, you just have to write {{ get_required_js_files() }} in your twig base template to load JS file.

Otherwise you have to import /bundles/eltharinautomaticcollection/js/automaticcollection.js manually

What is AutomaticCollection Bundle?

This bundle will render automatic add and delete elements for Collection Type.

When allow_add param will be set, the bundle will automaticly add a button for add a new row.

When allow_delete param will be set the bundle will automaticly add a delete row button on each line,

When allow_delete param is not set, you can have the delete button only for the new rows.

Use It :

As CollectionType, You have two Form Types:

PrincipalType :

class PrincipalType extends AbstractType
{
	public function buildForm(FormBuilderInterface $builder, array $options): void
	{
		$builder
			->add('numero')
			->add('libelle')
			->add('users', AutomaticCollectionType::class, [
						'entry_type' =>  SecondType::class,
						'allow_add' => true,
						'allow_delete' => true,
						'by_reference' => false,
						'add_button_string' => '<button type="button" class="automatic_collection_addBtn" data-collection-holder-class="{{ id }}">New</button>',
						'delete_button_string' => '<button type="button" class="btn danger automatic_collection_delBtn">Suppr</button>'
					]);
		;
	}

	public function configureOptions(OptionsResolver $resolver): void
	{
		$resolver->setDefaults([
			'data_class' => null,
		]);
	}
}

And SecondType :

class SecondType extends AbstractType
{
	public function buildForm(FormBuilderInterface $builder, array $options): void
	{
		$builder
			->add('lastname')
			->add('surname')
		;
	}

	public function configureOptions(OptionsResolver $resolver): void
	{
		$resolver->setDefaults([
			'data_class' => null,
		]);
	}
}

In PrincipalType, the options allow_add and allow_delete (from CollectionType) will automaticlly add buttons add and delete on each row.

When you add a new row, the button delete will be shown no matter that the allow_delete is at true.

you can change HTML button by replacing twig templates in your form template site or in same template :

{# if in same view don't forget this line to enable it #}
{% form_theme form _self %} 

{%- block automatic_collection_add_button_widget -%}
    <button type="button" class="automatic_collection_addBtn" data-collection-holder-class="{{ id }}">New</button>
{%- endblock automatic_collection_add_button_widget -%}

{%- block automatic_collection_delete_button_widget -%}
    <button type="button" class="btn danger automatic_collection_delBtn">Suppr</button>
{%- endblock automatic_collection_delete_button_widget -%}

don't forget to add classes automatic_collection_addBtn and automatic_collection_delBtn for JS and data-collection-holder-class="{{ id }}"

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core