control-group error not correctly set

Create issue
Issue #74 resolved
Former user created an issue

Current version of BootInput::getContainerCssClass seems to wrongly use the CHtml::resolveName($this->model, $this->attribute)

This causes the model to not resolve the attribute correctly and so it does not set the 'error' class to the control-group reverting to previous version of code fixes the problem

Comments (8)

  1. rmarin

    I think it's using it correctly, it's just the class "error" isn't being interpreted properly to the input element itself. You can try it (in-line through FF or Chrome) on Twitter Bootstrap's form example to apply the error class to the input itself and it won't change.

    According to their docs, this is what's required to render the element as expected (pretty much wrapping the label and input in a control group):

        <form class="form-horizontal">
        <legend>Legend text</legend>
        <div class="control-group">
        <label class="control-label" for="input01">Text input</label>
        <div class="controls">
        <input type="text" class="input-xlarge" id="input01">
        <p class="help-block">Supporting help text</p>

    I'm not sure what the best way to solve the problem because it also wraps the label (e.g. $form->labelEx()). I'm not sure if CActiveForm has something that allows us to easily render the label, input, and even a hint. Maybe a new method that's able to wrap it all together?

    I just started using Yii and Twitter Bootstrap (awesome extension!), but I'll give it a shot at a solution if you don't already have one in mind.

  2. Former user Account Deleted

    Are you sure this is resolved? I just updated my extension but the error classes are still not getting attached on server validation (client validation works correctly as in the previous versions). Do I need to use the bootstrap.min.css provided by you? Currently I'm compiling my own from Twitter's less files on github.

  3. Micha Wotton

    This is not fixed in either stable or default branches, specifically on a horizontal form.

    Changing the code in BootInput::getContainerCssClass() from this:

    $attribute = $this->attribute;
    return $this->model->hasErrors(CHtml::resolveName($this->model, $attribute)) ? CHtml::$errorCss : '';

    to this:

    $attribute = $this->attribute;
    return $this->model->hasErrors($attribute) ? CHtml::$errorCss : '';

    has resolved the issue for horizontal forms. I am using 0.9.12.r211.

  4. Log in to comment