Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting default classes on a per-form basis #217

Open
hackel opened this issue Feb 16, 2016 · 1 comment
Open

Allow setting default classes on a per-form basis #217

hackel opened this issue Feb 16, 2016 · 1 comment

Comments

@hackel
Copy link
Contributor

hackel commented Feb 16, 2016

Currently, default classes are set and read from the laravel-form-builder config file. This works fine most of the time, but I've come across several cases where I would like to change these for a particular form, but don't want to have to manually specify them for each form field. I propose adding another layer to pull default values from, in the form's $formOptions attribute. I think this would just be a matter of checking for a value first in FormField::allDefaults, and if found using that instead of the config file value. This way, you could do something like this:

class SomeForm extends Form
{
    protected $formOptions = [
        'defaults' => [
            'label_class'   => 'control-label',
            'wrapper_class' => 'col-sm-2',
        ],
    ];

    public function buildForm()
    {
        $this->add('inline-sub-form', 'form', [
            'class'        => $this->formBuilder->plain([
                'defaults' => [
                    'label_class'   => 'fancy-control-label',
                    'wrapper_class' => 'col-sm-11',
                ],
            ])->add('asdf', 'number'),
        ]);
    }
}

Thoughts? I thought I would throw this out there first, but I can do a PR.

@kristijanhusak
Copy link
Owner

It looks ok, you an work on PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants