2016-10-23 8 views
0

Wie ID in Select2 DropDownlist Kartik hinzufügen. Das Ziel, das ich will, wenn ich den Wert "Erfolg" im Dropdown-Menü wähle, ist der Wert in der anderen Dropdownliste Beispiel2 und Beispiel3 deaktiviert falsch. Zuvor ist für die Dropdownliste Beispiel2 und Beispiel3 mit dem Wert "Ja" der Wert false. Ich habe Code Javascript erstellt, ist aber nicht funktionieren. Ich weiß es nicht, bitte rate mir.Abhängige Dropdown-Funktion funktioniert nicht in yii2

Das ist mein Code:

<?php 
 
echo $form->field($model, 'example')->widget(Select2::classname(), [ 
 
    'model' => $model, 
 
    'hideSearch' => true, 
 
    'data' => ['success' => 'Success', 'fail' => "Fail"], 
 
    'language' => 'id', 
 
    'options' => [ 
 
     'placeholder' => 'Pilih', 
 
     'options' => [ 
 
      ['id' => 'example'], 
 
     ] 
 
    ], 
 
    'pluginOptions' => [ 
 
     'allowClear' => true, 
 
     'width' => '350px', 
 
     ], 
 
    ])->label('Example'); 
 
?> 
 

 
<?php 
 
echo $form->field($model, 'example2')->widget(Select2::classname(), [ 
 
    'model' => $model, 
 
    'hideSearch' => true, 
 
    'data' => ['yes' => "Yes", 'no' => "No"], 
 
    'language' => 'id', 
 
    'options' => [ 
 
     'placeholder' => 'Pilih', 
 
     'options' => [ 
 
      'yes' => ['disabled' => true], 
 
      ['id' => 'example2'], 
 
     ] 
 
    ], 
 
    'pluginOptions' => [ 
 
     'allowClear' => true, 
 
     'width' => '350px', 
 
     ], 
 
    ])->label('Example 2'); 
 
?> 
 

 
<?php 
 
echo $form->field($model, 'example3')->widget(Select2::classname(), [ 
 
    'model' => $model, 
 
    'hideSearch' => true, 
 
    'data' => ['yes' => "Yes", 'no' => "No"], 
 
    'language' => 'id', 
 
    'options' => [ 
 
     'placeholder' => 'Pilih', 
 
     'options' => [ 
 
      'yes' => ['disabled' => true], 
 
      ['id' => 'example3'], 
 
     ] 
 
    ], 
 
    'pluginOptions' => [ 
 
     'allowClear' => true, 
 
     'width' => '350px', 
 
     ], 
 
    ])->label('Example 3'); 
 
?>

Diese Javascript-Code:

<?php 
 
$this->registerJs(' 
 
$("input[type=dropdown]").change(function() { 
 

 
    var isi = this.value; 
 
    if(isi == "success") { 
 
     $("#example2").attr("disabled",false); 
 
     $("#example3").attr("disabled",false); 
 
    } 
 

 
}); 
 
') 
 
?>

+0

Was meinst du? Geben Sie ein Beispiel dafür, wie Sie dies möchten. – Bizley

Antwort

0

Kann sein, das ist, was Sie wollen. Option zum ersten Element auswählen (#beispiel):

+0

Wo ist die Platzierung des Codes? Ich habe versucht, Drop-Down mit ID "Beispiel", und das Ergebnis ist fehlgeschlagen. – CrashBurn

+0

unter _'pluginOptions'_ im Beispielfeld. –

+0

Kann immer noch nicht @ Wilson Ng – CrashBurn