Issue #247 invalid

$htmlOptions array cleared somehow inside TbActiveForm::error()

Tomasz Trejderowski
created an issue

Either I'm missing something obvious or Yii-Bootstrap / Yii-Booster extensions are somehow clearing (changing) $htmlOptions array used in TbActiveForm::error() and problably in some other places.

First, let's take a look, how this works when using base classes (CActiveForm).

This is the code in form view:

<?php 
    $validationArray = array
    (
        'hideErrorMessage'=>TRUE,
        'afterValidateAttribute'=>'js:afterValidateAttribute'
    );
?>

<?php echo('<pre>$validationArray = '.print_r($validationArray, TRUE).'</pre>'); ?>

<div class="row">
    ...
    <?php echo($form->error($model, 'name', $validationArray)); ?>
</div>

additional print_r() and die() are added as the first line of CActiveForm::error() function, to compare array that is passed and array that is received.

Running such configured script results in following screen output:

$validationArray = Array
(
    [hideErrorMessage] => 1
    [afterValidateAttribute] => js:afterValidateAttribute
)

$htmlOptions = Array
(
    [hideErrorMessage] => 1
    [afterValidateAttribute] => js:afterValidateAttribute
)

What comes in must comes out, so everything is fine.

Now, take a look, what happens, when using TbActiveForm instead.

This is the view code (quite similar):

<?php 
    $validationArray = array
    (
        'hideErrorMessage'=>TRUE,
        'afterValidateAttribute'=>'js:afterValidateAttribute'
    );
?>

<?php echo('<pre>$validationArray = '.print_r($validationArray, TRUE).'</pre>'); ?>

<?php echo($form->textFieldRow($model, 'name', $htmlOptions + array('prepend'=>'Imię'))); ?>
<?php echo($form->error($model, 'name', $validationArray)); ?>

additional print_r() and die() are added as the first line of TbActiveForm::error() function as well.

And this is the screen output:

$validationArray = Array
(
    [hideErrorMessage] => 1
    [afterValidateAttribute] => js:afterValidateAttribute
)

$htmlOptions = Array
(
)

What is going on here? Why this array is being cleared and where?

Comments (1)

  1. Tomasz Trejderowski reporter

    This is invalid. Missed out, that htmlOptions for particular elements are passed not at first level of array, but rather as subarrays -- i.e. errorOptions, prependOptions, labelOptions etc.

  2. Log in to comment