Q:

Is there any way to bind drop down field options to specific input type in yii2

I have a form which consists of media type drop down. 
<?= $form->field($model, 'media_type')->dropDownList(
    [
        'text' => 'Text',
        'image' => 'Image',
        'url' => 'Url',
        'audio' => 'Audio',
        'video' => 'Video',
    ], 
    [
        'options' => ['prompt' => 'Select Media Type']
    ]
) ?>

I wants to change value field when changing media type in yii2 form. For example, if we select text option then we need to show tinymce editor. Or if we select image then we need to show file input field. 
File input field
<?php
    echo $form->field ( $model, 'value' )->fileInput ();
    if ($model->value != ""){
        echo Html::a('Click here to view image', $model->value, ['target' => '_blank']);
    }
?>

Tiny mce editor
<?= $form->field($model, 'value')->textarea(['rows' => 6])->widget(letyii\tinymce\Tinymce::className(), [
    'options' => [
        'class' => '',
    ],
    'configs' => [ 
        'plugins' => 'advlist autolink link lists charmap preview code colorpicker',
        'height' => 300,
        'selector' => 'textarea',
        'forced_root_block' => '',
    ],
]); 
?>

Is there anyway to achieve this will be very helpful
Thanks

A:

Add some JavaScript that listens to the change of the dropdown and show/hide your elements based on the selected value.
I wrote a small example. You'll have to change the IDs to match your elements and maybe make some other small changes, but something like this should work.
<?php
$this->registerJs("
    $(function() {
        $('#your-form-media-type-id').on('change', function() {
            var value = this.value
            switch (value) {
                case 'text':
                    $('#your-mce-div').show();
                    $('#your-image-input-div').hide();
                break;

                case 'image':
                    $('#your-image-input-div').show();
                    $('#your-mce-div').hide();
                break;
            }
        });
   });
");

