Skip to content

bootstrap ActiveField config not applied #136

@yii-bot

Description

@yii-bot

This issue has originally been reported by @Stevad at yiisoft/yii2#6312.
Moved here by @cebe.


What I try to do:

  1. create own ActiveField class with changed template and horizontalCssClasses
namespace app\components;
class ActiveField extends \yii\bootstrap\ActiveField
{
    public $template = "{label}\n{beginWrapper}\n{input}\n{error}\n{hint}\n{endWrapper}";

    public $horizontalCssClasses = [
        'offset' => 'col-sm-offset-3',
        'label' => 'col-sm-3',
        'wrapper' => 'col-sm-6',
        'error' => '',
        'hint' => '',
    ];
}
  1. then I use my class in ActiveForm:
<?php $form = ActiveForm::begin([
        'fieldClass' => 'app\components\ActiveField',
        'layout' => 'horizontal'
    ]); ?>
...

But if I dump some field like $form->field($model, 'name') I see that template and horizontalCssClasses not changed (their values are default from native \yii\bootstrap\ActiveField).

Dump:

object(app\components\ActiveField)[136]
  public 'template' => string '{label}
{beginWrapper}
{input}
{error}
{endWrapper}
{hint}' (length=58)
  public 'horizontalCssClasses' => 
    array (size=5)
      'offset' => string 'col-sm-offset-3' (length=15)
      'label' => string 'col-sm-3' (length=8)
      'wrapper' => string 'col-sm-6' (length=8)
      'error' => string '' (length=0)
      'hint' => string 'col-sm-3' (length=8)
  public 'inline' => boolean false
  public 'inputTemplate' => null
...

instead of

object(app\components\ActiveField)[136]
  public 'template' => string '{label}
{beginWrapper}
{input}
{error}
{hint}            <-- hint before endWrapper
{endWrapper}' (length=58)
  public 'horizontalCssClasses' => 
    array (size=5)
      'offset' => string 'col-sm-offset-3' (length=15)
      'label' => string 'col-sm-3' (length=8)
      'wrapper' => string 'col-sm-6' (length=8)
      'error' => string '' (length=0)
      'hint' => string '' (length=0)          <-- hint value must be empty
  public 'inline' => boolean false
  public 'inputTemplate' => null
...

I think this is error in \yii\bootstrap\ActiveField class.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions