From 3d45e7923a977b756daec9154572219235221720 Mon Sep 17 00:00:00 2001 From: Sebastian Klatte Date: Mon, 2 Jun 2014 15:17:26 +0200 Subject: [PATCH] mark default radio button selected with bootstrap active class sample: echo $this->Form->input('start_minutes', array( 'type' => 'radio', 'class' => 'btn btn-default', 'div' => false, 'legend' => false, 'hiddenField' => false, 'default' => '0', 'options' => array('0' => __('now'), '15' => __('in 15 min.'), '30' => __('in 30 min.')))); --- View/Helper/BoostCakeHtmlHelper.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/View/Helper/BoostCakeHtmlHelper.php b/View/Helper/BoostCakeHtmlHelper.php index 2965a51..1cf25f8 100644 --- a/View/Helper/BoostCakeHtmlHelper.php +++ b/View/Helper/BoostCakeHtmlHelper.php @@ -25,6 +25,12 @@ public function useTag($tag) { if ($tag === 'radio') { $regex = '/()/'; if (preg_match($regex, $html, $match)) { + + if((strpos($class, 'btn') !== false) && ($args[3]['checked'] == 'checked')) + { + $class .= ' active'; + } + $html = $match[1] . ' class="' . $class . '"' . $match[2] . preg_replace($regex, ' ', $html); } } @@ -71,4 +77,4 @@ public function image($path, $options = array()) { return parent::image($path, $options); } -} \ No newline at end of file +}