contributte / forms-multiplier

:repeat: Form multiplier & replicator for Nette Framework
https://contributte.org/packages/contributte/forms-multiplier.html
MIT License
26 stars 21 forks source link

Upgrade from Kdyby\FormsReplicator 1.x #112

Open JanK007 opened 1 week ago

JanK007 commented 1 week ago

Hello everybody,

I was tasked with upgrading an old application written in PHP 5.6 and Nette 2.3 to PHP 8.1+. I gradually replaced individual libraries and got to PHP 8.1, Nette 3.1 (unfortunately to Nette\Utils 4) but stayed at Latte 2. Unfortunately Nette\Utils 4 blocks me from using the old Kdyby\FormsReplicator. I found the Contributte\Forms-multiplier library. Unfortunately, due to using Latte 2, I cannot use a higher version of the library than 3.2. In this version, I tried the default examples that worked me, but I ran into a few problems in the application that I can't quite get around: 1) when setting default values ​​to the replicator when rendering the form, the defined buttons do not see it: Multiplier->detachCreateButtons(): void Nette\InvalidArgumentException: Component with name 'multiplier_creator' does not exist (apparently they are not yet added to the appropriate container)

2) I did not manage to define nested multipliers (multiplier in multiplier) even in the test case, which it used several times in that application

3) custom rendering (not through the macros) of repeatable components within the template is not working for me

Can Contributte\Forms-multiplier in version 3.2 even solve these problems? Would switching to Latte 3 and thus the possibility of upgrading the library to version 4.* help me? Can a newer version of the library address these issues? Should I use some other library? Any other advices or examples?

I will be very grateful for any good advice. Thank you.

jtojnar commented 1 week ago

Unfortunately, we do not have resources to support the older versions. I can barely scrounge up enough time to maintain the primary version.

when setting default values ​​to the replicator when rendering the form, the defined buttons do not see it: Multiplier->detachCreateButtons(): void Nette\InvalidArgumentException: Component with name 'multiplier_creator' does not exist (apparently they are not yet added to the appropriate container)

It is not clear to me what you mean. It would be helpful if you could create a minimal reproducible example against 4.0/master.

I did not manage to define nested multipliers (multiplier in multiplier) even in the test case, which it used several times in that application

Nested multipliers are known to be buggy in some cases. I wanted to fix that after #103 but other projects took priority.

custom rendering (not through the macros) of repeatable components within the template is not working for me

Not sure what you mean.

I found the Contributte\Forms-multiplier library. Unfortunately, due to using Latte 2, I cannot use a higher version of the library than 3.2.

If you do not use the latte macros and register the class manually, instead of using the DI extension. Latte is not actually required so you might be able to install it by removing the conflict:

https://github.com/contributte/forms-multiplier/blob/47e0d11a5595ba0cc7e9a12d687bb54a28e7252d/composer.json#L28

Should I use some other library?

Unfortunately, I am not aware of any. I became a (partial) maintainer of this project because I also needed to upgrade a project that depended on Kdyby\FormsReplicator. But the project itself is minor thing I do in a free time so I can only spend so much time on maintaining its dependencies.

If your project depends on component like this you could also consider contributing fixes here.

JanK007 commented 6 days ago

First of all, thank you for your reply. I programmer but not very familiar in PHP/Nette technologies. I work in PHP/Nette maximally several weeks per year.

It is not clear to me what you mean. It would be helpful if you could create a minimal reproducible example against 4.0/master.

I tried to create some simple example. It seems that it works with latest version. So I will see if it will be possible to upgrade. I have yet only one problem with empty multiplier that has in my page 1 empty record. That is unwanted. I tried to remove it by setting minCopies to 0 or setValues to empty array but unsuccessfully.

...
$multiplier->setMinCopies(0);
...
$multiplier->setValues([], true);
...

Nested multipliers are https://github.com/contributte/forms-multiplier/issues/56 in some cases. I wanted to fix that after https://github.com/contributte/forms-multiplier/pull/103 but other projects took priority.

Can you specify what is the time we are talking about? Weeks, months? First quarter of next year?

custom rendering (not through the macros)

I mean "manual rendering" in latte template: Kdyby/FormsReplicator. It works me now with version 4.0/master.

If you do not use the latte macros and register the class manually, instead of using the DI extension.

Can you write your idea more explicitly? Download library separately, add to project manually and manually register Multiplier::class into Nette? Can you give me some advice/link how to do it?

Thank you very much for your comments.