Speaktech.in

Yii2 Radio Button list in activeform and checked value

Yii2 Radio Button list display in activeform. Radio button selected value in jquery.



<?php

  $lamination = PaperRates::find()
                        ->select(["PaperRateLamination as value","if(PaperRateLamination =1,'Yes','No') as id"])
                          ->asArray()
                        ->all();

$lamin = ArrayHelper::map($lamination,'value','id');

?>
                             <?=  $form->field($model, 'PrintOrderLineColor',['options' => ['id' => 'paperColor']])
                                                    ->radioList(
                                                              $lamin,
                                                        [
                                                            'item' => function($index, $label, $name, $checked, $value) {

                                                                $return = '<label >';
                                                                $return .= '<input type="radio" style="display: none;" name="' . $name . '" value="' . $value . '" tabindex="3">';
                                                                $return .= '<i></i>';
                                                                $return .= '<span class="btn outer-success">' . ucwords($label) . '</span>';
                                                                $return .= '</label>';

                                                                return $return;
                                                            }
                                                        ]
                                                    )
                                                ->label(false);
                                                ?>




                         


                             <?=  $form->field($model, 'PrintOrderLineColor',['options' => ['id' => 'paperColor']])
                                                    ->radioList(
                                                        [1 => 'Black and White', 2 => 'Color'],
                                                        [
                                                            'item' => function($index, $label, $name, $checked, $value) {

                                                                $return = '<label >';
                                                                $return .= '<input type="radio" style="display: none;" name="paperColorName" value="' . $value . '" tabindex="3">';
                                                                $return .= '<i></i>';
                                                                $return .= '<span class="btn outer-success">' . ucwords($label) . '</span>';
                                                                $return .= '</label>';

                                                                return $return;
                                                            }
                                                        ]
                                                    )
                                                ->label(false);
                                                ?>


in jqurey to get checked value of radio button list:


$paperColor = $("input:radio[name=paperColorName]:checked").val();