onchange function in dropDownList yii2

2019-09-16 01:47发布

问题:

I have a function (getArticleByFamille) in event onchange dopDownList like this:

<?= $form->field($modelFamille, 'idFamille')->dropDownList(
    ArrayHelper::map(Famille::find()->all(), 'idFamille', 'libelle'),
    [
        'prompt' => 'Sélectionner la Categorie',
        'class' => 'chosen-select mb-15',
        'onchange' => 'getArticleByFamille(this.value,"vente/devis","' . Yii::$app->getUrlManager()->getBaseUrl() . '","ArticleByFamille")'
    ]
)->label(false); ?>

but When I call this function, it not working and when I inspect I have this code:

onchange="getArticleByFamille(this.value,&quot;vente/devis&quot;,&quot;/performancia/web&quot;,&quot;ArticleByFamille&quot;)"

quote was changed

回答1:

It is because occurs encoding (enabled by default).

Try this (not tested):

[
    'prompt'   => 'Sélectionner la Categorie',
    'class'    => 'chosen-select mb-15',
    'onchange' => new \yii\web\JsExpression( 'getArticleByFamille(this.value,"vente/devis","' . Yii::$app->getUrlManager()->getBaseUrl() . '","ArticleByFamille")' )
]