kristijanhusak / laravel-form-builder

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

Plain HTML field and groups #299

Open frenzyk opened 7 years ago

frenzyk commented 7 years ago

It would be great to have plain HTML field. For example to generate headers. Now I have to do such hack:

 protected function addHeader($headerText)
    {
        $this
            /* Main Information */
            ->add('header' . $this->headerCounter, 'static', [
                'tag' => 'h3',
                'wrapper' => false,
                'attr' => ['class' => 'section-header clear'],
                'value' => $headerText,
                'label_show' => false,
            ])
            ->add('hr' . $this->headerCounter, 'static', [
                'tag' => 'div',
                'wrapper' => false,
                'attr' => ['class' => 'section-header'],
                'value' => '<hr/>',
                'label_show' => false,
            ]);

        $this->headerCounter++;
    }

Nothe that without headerCounter there will be Field [header] already exists in the form InvalidArgumentException. Assume some internal name iterator for such things or some flag with condition, like this: vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/Form.php:218

        if ($field->isUnnamed()) {
            $this->fields[] = $field;
        } else {
            $this->fields[$field->getRealName()] = $field;
        }

Also sometime I feel great need for wrapping groups of elements (for horisontal aligment or to make tabs, for example). Assume some similar to routes grouping logic. Although I know it hard to implement=( For now I have to use custom fields to generate close/open tag

kristijanhusak commented 7 years ago

I had these requests before, but i still do not agree to add them. This package will not magically print everything with one form() method, at least it cannot cover all use cases. If you need to add some static html to the page, just split the form with the form helpers, and add the static html in between. More info here. http://kristijanhusak.github.io/laravel-form-builder/form/viewhelpers.html