slywalker / cakephp-plugin-boost_cake

Bootstrap Plugin for CakePHP
http://slywalker.github.io/cakephp-plugin-boost_cake/
278 stars 93 forks source link

Wrong value for attribute "for" in label with type radio #37

Closed ker0x closed 10 years ago

ker0x commented 10 years ago

Hello,

Congratulations for your plugin, it's very useful.

However, I noticed that when defining the type of the "input" to radio, the attribute "for" to "label" displays twice the form name :

<label class="radio" for="BoostCakeBoostCakeRadio1">
    <input id="BoostCakeRadio1" type="radio" value="1" name="data[BoostCake][radio]">
    Option one is this and that—be sure to include why it's great
</label>
slywalker commented 10 years ago

Thank you. It is typo ...

ker0x commented 10 years ago

I wasn't referring to the typo. I thought the plugin had a bug that doubled the name of the model in the "for" attribute of the "label" when an "input" was of type "radio".

In fact it's the FormHelper itself that generates the problem. I've solved this by adding some code to the end of the FormHelper in the plugin.

public function label($fieldName = null, $text = null, $options = array()) {
    if ($this->_inputType === 'radio') {
        $regex = '/' . current($this->entity()) . '/';
        $fieldName = preg_replace($regex, '', $fieldName);
    }

    return parent::label($fieldName, $text, $options);
}

I hope it will help others with the same problem.

Anyway, sorry for the confusion ;) !

slywalker commented 10 years ago

I confirmed the error in CakePHP 2.4.0. There is no error from CakePHP 2.4.1 version.