Prevent encoding in htmlOption

Hi I need to call a javascript in one of textField so I wrote like this :


<?php echo $form->textField($model,'barang_id',array('onchange'=>'refreshNama("#MasukBarang_barang_id", "#barangkode")')); ?>

But the Yii will encode the string causes the javascript is invalid. I’ve tried add ‘encode’=>‘false’ but I don’t feel this the right one, I thought it somekind like add prefix “js:” in front of the string. I’ve tried that too, but the string still encoded.

Does anybody know how to fix this?

I tryed it now and it’s working but you have to pay attention to the use of single/double quote…

use it like this




<?php 

   echo $form->textField($model,'barang_id',array(

          'encode'=>false,

          'onchange'=>"refreshNama('#MasukBarang_barang_id', '#barangkode')"

    )); 

?>




that way you get this


<input onchange="refreshNama('#MasukBarang_barang_id', '#barangkode')" ... 

NOTE: if you use the double quotes in the function call you get this code that is not OK


input onchange="refreshNama("#MasukBarang_barang_id", "#barangkode")" ...

yeah, that ones can do.

I just wonder isn’t there something like prefix “js:” to prevent encode? But I am not quite sure where can use this prefix.

So for now I am using your way, mdomba …

thank you :)

My was as you say is per documentation… hehe…

check what the documentation says under the attribute $htmlOptions for tag() method - http://www.yiiframew…Html#tag-detail

I see the


'encode' => false

option does not exist in Yii2. How do I achieve the same result?