2014-11-25 124 views
1

添加onchange事件这是我的代码:Yii2 - 如何的ActiveForm

<?= $form->field($model, 'int_roomCatId') 
      ->dropDownList(ArrayHelper::map(TblCategory::find()->all(), 'int_category_id', 'str_category'), array('class' =>'form-control','prompt'=>'Select Room Category')) 
      ->label('Room Category'); ?> 

我想补充的onchange = “的getData()” 事件。在哪里添加这个?

回答

1

在你htmloptions阵列只是做象下面这样:

dropDownList(ArrayHelper::map(TblCategory::find()->all(), 'int_category_id', 'str_category'), array('onchange'=>'getData()','class' =>'form-control','prompt'=>'Select Room Category')) 

htmloptions阵列每个键和值将被转换为HTML属性,例如:

'key'=>'value' 

将显示为:

<tag key="value" /> 
1

您可以拨打以下电话:

<?= $form->field($model, 'product_name')->dropDownList(ArrayHelper::map(Products::find()->all(), 'id', 'name'), 
      ['prompt'=>'-Choose a Product-', 
       'onchange'=>' 
       $.get("index.php?r=suborders/listprice&id="+$(this).val(), function(data) { 
        $("#suborders-product_price").val(data); 
       }); 
      ']); 
    ?> 

希望这对你有所帮助。

0

我是这样做的:

echo $form->field($flightSearchForm, "lastDepartTimeChange", 
     ['options' => ['class' => 'col-xs-12', 
         'onchange' => "changeHidden(\"departFlightTimeMin\")"] 
     ])->widget(\yii\jui\SliderInput::classname()); 

正如你所看到的,我只是把它的HTML选项数组这是第三输入$形式 - >字段功能研究。希望这可以帮助!

相关问题