ActiveForm Radio Buttons

Hi hi,

I’m quite new to Yii and need help with the ActiveForm and Radio Buttons.

Question 1: Do I need to use "radioList" for Radio Buttons, so far "radio" is working for me.

The thing is, every radio button is releated to a div. When I click a radio button another part of the form gets visible by JavaScript. Here my raw code structure (yes I know this is not valid HTML)


<form>

<input>

<input>

<input>

<hr>

<radio>

<div><input><input><input></div>

<hr>

<radio>

<div><input><input><input></div>

<hr>

</form>

so I think, for me a radioList won’t work. Any ideas?

Question 2: Is there a way to check a radio button by default? All answers here won’t do the job for me.

Question 3: How to remove the auto generated hidden radio field or how to pass it a value?

Thanks for any help!

Q1: use radioList

http://www.yiiframework.com/doc-2.0/yii-bootstrap-activefield.html#radioList()-detail

Q2:

Since activeField radiolist() is attached to $model, it is enough to set model attribute to desidered value.

For example:




$model->myattribute = 1;

echo $form->field($model, 'myattribute')->radioList( [0=>'zero', 1 => 'one', 2 => 'two'] );



Q3:

Use options field, passing proper unselect value:

http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#activeRadioList()-detail




echo $form->field($model, 'myattribute')->radioList( [0=>'zero', 1 => 'one', 2 => 'two'], ['unselect' => null] );



Thank you Fabrizio for your fast answers.

Q1:Now something strange happens, why is there Delivery Methode. How to remove it? Yes css would do it, but that is not a clean way.

7624

Bildschirmfoto 2018-03-08 um 14.44.20.png

Q2: Is there a trick to pass every radio in the radioList a separate id. That would make my work a lot easier. Thanks for any help!

Q1: Probably the label "Delivery Methode" is the label of attribute. So set label to false to hide the label.




echo $form->field($model, 'myattribute')->label(false)->radioList( [0=>'zero', 1 => 'one', 2 => 'two'] );



Q2: Check radiolist options: http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#activeRadioList()-detail

Maybe you can use item callback to customize them.

Great, thank you so much Fabrizio. Your tips did the job perfect!

my bk experience

Did it work for you, I still facing some issue.

The solution also works for me perfectly. Thanks all