Yii 2
I have following field on form ActiveForm:
<div class="col-sm-4">
<?= $form->field($model, 'amount',
['options' => ['class' => 'form-group form-inline'],
'onchange' => "
if($('#dss-move_type').val() === '0'){
var num = $(this).val();
num = num <= 0 : num ? -num;
$(this).val(num);
}"]) ?>
</div>
But get error: Setting unknown property: yii\bootstrap\ActiveField::onchange
How correct add option event onchange for field ActiveForm?
This might not be the answer to your question, but it will do what you want. Add the following to your view file:
$this->registerJs(
"$('#element_id').on('change', function (){
if($('#dss-move_type').val() === '0'){
var num = $(this).val();
num = num <= 0 : num ? -num;
$(this).val(num);
}
});"
);