echo $form->field($model, 'id_ente')->dropDownList( ArrayHelper::map(Entes::find()->where(['id_sector' => 2])->orderBy('nombre_ente')->all(), 'id_ente', 'nombre_ente'), ['prompt' => 'Seleccione ', 'id' => 'id-ente'] ); <div class="col-xs-3" style="display: block;" id="id_linea"> <?= $form->field($model, 'id_linea')->dropDownList(ArrayHelper::map(Lineasaereas::find()->orderBy('nombre_linea')->all(), 'id_linea', 'nombre_linea'), ['prompt' => 'Seleccione ', 'id' => 'id-linea']); ?> </div> <script> document.addEventListener('DOMContentLoaded', function() { const enteSelect = document.getElementById('id-ente'); const lineaSelect = document.getElementById('id-linea'); enteSelect.addEventListener('change', function() { const selectedValue = enteSelect.value; // Limpiar las opciones del dropdown de líneas lineaSelect.innerHTML = ''; // Obtener todas las líneas disponibles const lineas = <?= json_encode(ArrayHelper::map(Lineasaereas::find()->orderBy('nombre_linea')->all(), 'id_linea', 'nombre_linea')); ?>; // Agregar la opción de "Seleccione" lineaSelect.innerHTML += '<option value="">Seleccione</option>'; // Agregar las opciones según la selección del ente for (const [id, nombre] of Object.entries(lineas)) { // Si el ente es Inac (id_ente 28), omitir Conviasa (id_linea 1) y Aerostal (id_linea 2) if (selectedValue == 28 && (id == 1 || id == 2)) { continue; // No agregar estas líneas si el ente es Inac } lineaSelect.innerHTML += `<option value="${id}">${nombre}</option>`; } }); }); </script>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter