kristijanhusak / laravel-form-builder

Laravel Form builder for version 5+!
https://packagist.org/packages/kris/laravel-form-builder
MIT License
1.7k stars 296 forks source link

use specific language_name in a ChildForm Collection #728

Closed ELtd closed 2 weeks ago

ELtd commented 3 weeks ago

Hello,

I use a specific form in two collections. I don't want to have the same labels in the two. We should be able to force the language name in the options of the collection.

Form A [
      Collection A1 [
            Form B
       ],
      Collection A2[
            Form B
       ]
]

To fix the problem :

https://github.com/kristijanhusak/laravel-form-builder/blob/ee4f8f1c41593f8f747e98b96355ba57f13a3be8/src/Kris/LaravelFormBuilder/Fields/ChildFormType.php#L119

- 'language_name' => $this->parent->getLanguageName(),
+ 'language_name' => $this->getOption('language_name') ?: $this->parent->getLanguageName(),

Then this code works as expected :

$this->add('A1', 'collection',
        [
            'type' => 'form',
            'options' => [
                'class' => B::class,
                'language_name'=>'models.A1.B',
            ]
        ]);

Thank you for your package !

rudiedirkx commented 2 weeks ago

Looks good. PR please.

I never use the 'language name' - I always explicitly set label for every field - so I can't test it, but it looks safe enough.

rudiedirkx commented 2 weeks ago

Fixed in #729