Reputation: 978
I have two radioList bindend to two different fields:
<div class="form-group row">
<div class="col-lg-5">
<?= $form->field($model, 'isGdo')->radioList([0 => 'No', 1 => 'Yes'])->label("Are you a distributor ?"); ?>
</div>
<div class="col-lg-5">
<?= $form->field($model, 'isProducer')->radioList([0 => 'No', 1 => 'Yes'])->label("Are you a producer?"); ?>
</div>
</div>
Now my aim is to refactor this and create a radioList with 3 options in which I can set both these properties.
I know that I can switching to a single field with 3 values, but there are a lot of checks in the program, so keeping these two fields separate could be better for me.
Upvotes: 0
Views: 321
Reputation: 3079
Create A radio 3 radio buttons for showing with same name.
isGdo and isProducer
kept as hidden input field . Write jquery code on above radio button and set that value on input box on basis of selection of radio button.
echo $form->field($model, 'isGdo')->hiddenInput(['value'=>''])->label(false);
echo $form->field($model,'isProducer')->hiddenInput(['value'=>''])->label(false);
$form->field($model, 'publicattribute')->radioList([1 => 'yes', 0 => 'No'])->label('');
<script>
$(document).ready(function(){
$("input[type='button']").click(function(){
var radioValue = $("input[name='']:checked").val();
if(radioValue){
alert("Your are a - " + radioValue);
**insert that value on your condition in the hidden input field**
}
});
});
</script>
Upvotes: 1