kristijanhusak / laravel-form-builder

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

Bugs when modding multiple times with `multiple` #677

Open ukeloop opened 2 years ago

ukeloop commented 2 years ago

Bugs when modding multiple times with multiple.

https://github.com/kristijanhusak/laravel-form-builder/issues/305 related bugs.

$options = [
    'choices' => ['en' => 'English', 'fr' => 'French'],
    'choice_options' => [
        'wrapper' => ['class' => 'choice-wrapper'],
        'label_attr' => ['class' => 'label-class'],
    ],
    'expanded' => true,
    'multiple' => true
];

$this->plainForm->add('test', 'choice', $options);

echo $this->plainForm->test->getName(); // test
var_dump($this->plainForm->test->getOption('tmp.multipleBracesSet')); // Null

$this->plainForm->modify('test', 'choice', [
    'rules' => 'required',
]);

echo $this->plainForm->test->getName(); // test[]
var_dump($this->plainForm->test->getOption('tmp.multipleBracesSet')); // true

$this->plainForm->modify('test', 'choice', [
    'rules' => 'required',
]);

echo $this->plainForm->test->getName(); // test
var_dump($this->plainForm->test->getOption('tmp.multipleBracesSet')); // true

I think codes of modding name should move to render method and remove side effects.

https://github.com/kristijanhusak/laravel-form-builder/blob/735c258e3ac3e524226eee5d898aec07e4812594/src/Kris/LaravelFormBuilder/Fields/FormField.php#L293-L296

rudiedirkx commented 2 years ago

The choice type is broken is several ways. All ParentType fields are somewhat broken. I'm starting v2 without it.

Eloar commented 1 year ago

I have feeling #705 might resolve that issue