Reputation: 305
In my dropdownlist, when I choose Percentage
, the label of the 'vendorcommision'
(next field) should be "Percentage"
. When I choose Amount
, the label should be "Amount"
if($model->userType!="ADMIN" && $model->userType!="HOST"){
echo $form->field($model, 'fixedOrPercentagevendor')
->dropDownList(
[0=>'Amount',1=>'Percentage'],
[
'onchange'=>'if($(this).val() == 1){
$("#percentage").val("20");
}
else{
$("#percentage").val("1000");}'
]);
echo $form->field($model, 'vendorcommision')
->label('Vendor Fee')
->textInput(['type' => 'number','id' => 'percentage']);
}
Upvotes: 0
Views: 744
Reputation: 168
Here is how I would do it:
->label(false)
]<span class="custom-label"></span>
Add event listener to the dropdown list to change labels. It will be on the lines of:
var onChangeFunc = function(event) {
if($(fixedOrPercentagevendorSelector).val() == 1) {
$('.custom-label').html('Percentage');
} else {
$('.custom-label').html('Amount');
}
}
Note: If you include I18N support to your project, you will probably have to save the labels in some variable and use them.
Upvotes: 1