yiisoft / yii2-bootstrap4

Yii 2 Bootstrap 4 Extension
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
216 stars 106 forks source link

Changed checkbox and radio options behavior #167

Closed simialbi closed 5 years ago

simialbi commented 5 years ago

Introduced $checkOptions to make checkboxes fully configurable via widget factory.

Q A
Is bugfix? ✔️
New feature? ✔️
Breaks BC?
Tests pass? ✔️
Fixed issues #165

I'm not sure if this is the best way to go. But it would make it possible to override all classes via config like this:

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'extensions' => require __DIR__ . '/../vendor/yiisoft/extensions.php',
    'container' => [
        'definitions' => [
            'yii\bootstrap4\ActiveField' => [
                'checkTemplate' => "<div class=\"form-check\">\n{input}\n{label}\n{error}\n{hint}\n</div>",
                'radioTemplate' => "<div class=\"form-check\">\n{input}\n{label}\n{error}\n{hint}\n</div>",
                'checkHorizontalTemplate' => "{beginWrapper}\n<div class=\"form-check\">\n{input}\n{label}\n{error}\n{hint}\n</div>\n{endWrapper}",
                'radioHorizontalTemplate' => "{beginWrapper}\n<div class=\"form-check\">\n{input}\n{label}\n{error}\n{hint}\n</div>\n{endWrapper}",
                'checkOptions' => [
                    'class' => ['widget' => 'form-check-input'],
                    'labelOptions' => [
                        'class' => ['widget' => 'form-check-label']
                    ],
                    'wrapperOptions' => [
                        'class' => ['widget' => 'form-check']
                    ]
                ]
            ]
        ]
    ]
];
samdark commented 5 years ago

Merged. Thank you!