kartik-v / yii2-widget-activeform

Enhanced Yii2 active-form and active-field with full bootstrap styling support (sub repo split from yii2-widgets).
http://demos.krajee.com/widget-details/active-form
Other
64 stars 35 forks source link

ActiveField ignores inputOptions['class'] #71

Closed WJRovers closed 8 years ago

WJRovers commented 8 years ago

Greetings,

I've found a possible bug in your ActiveField and the way it handles the inputOptions, class in specific.

Some example code to help you reproduce the bug:

//The form used
$form = ActiveForm::begin([
    'id'         => 'myId',
    'action'     => 'settings/save',
]);

echo Html::activeHiddenInput($model, 'key');
echo $form->field($model, 'value', [
    'inputOptions' => [
        'class' => 'form-control test',
        'style' => 'background: red'
    ]
])->label('My awesome label');

ActiveForm::end();

Will result in different view files depending on what type of activeForm is used.

use kartik\form\ActiveForm;
<input type="text" id="config-value" class="form-control" name="Model[value]" value="theValue" style="background: red">

As you can see it is only using the default form-control but not adding the test class! However it did add the background color of red.

use yii\widgets\ActiveForm;
<input type="text" id="config-value" class="form-control test" name="Model[value]" value="theValue" style="background: red">

Default ActiveForm does however add the test class.

Hope you can tell me what is wrong, what I am doing wrong of how to fix this. Thanks in advance for all your great libraries!

nicovicz commented 8 years ago

the workaround is use addClass property but you must also add default class 'form-control'

WJRovers commented 8 years ago

@nicovicz Are you sure this works?, haven't tested it myself yet.

The default class is 'form-control' so adding a class should ''add'' not ''set'' the classes, so that seems like bad a bad name for the function if it does that. On top of that it is really hard to style the input field. The add-class can only be called on the surrounding container (the form in this case).

Since the kartikk ActiveField extends the Yii2/ActiveField I expected it to just support the base functionalities. Guess it can only be done with a 'workaround'...

kartik-v commented 8 years ago

One of the following would work for your use case

echo $form->field($model, 'value')->label('My awesome label')->textInput([
    'class' => 'form-control test',
    'style' => 'background: red'
]);