jan.fleck
(jan.fleck@marc-cain.de)
March 8, 2018, 10:26am
1
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] );
jan.fleck
(jan.fleck@marc-cain.de)
March 8, 2018, 1:52pm
3
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
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.
jan.fleck
(jan.fleck@marc-cain.de)
March 9, 2018, 8:20am
5
Great, thank you so much Fabrizio. Your tips did the job perfect!
Richard935
(Richard935)
September 22, 2018, 11:20am
6
my bk experience
Did it work for you, I still facing some issue.
peter08
(peter08)
January 31, 2019, 5:30pm
8
The solution also works for me perfectly. Thanks all