I'm using Materialize CSS, I have a screen where I would like the Switch to be activated, the closest select
becomes active so the user can select an option, and if the Switch goes back to inactive the select
also come back to the inactive state.
HTML
<form id="relatorio" name="relatorio" class="col s12">
<div class="row">
<div class="input-field col s4 l4">
<select id="filtro2" name="filtro2" disabled>
<option value="" disabled selected>Filtro</option>
<option value="1">Opção 1</option>
<option value="2">Opção 3</option>
<option value="3">Opção 3</option>
</select>
<label>Filtro</label>
</div>
<div class="switch col s2 l2">
<div class="switch">
<label>
Não
<input type="checkbox">
<span class="lever"></span>
Sim
</label>
</div>
</div>
<div class="input-field col s4 l4">
<select id="filtro" name="filtro" disabled>
<option value="" disabled selected>Filtro</option>
<option value="1">Opção 1</option>
<option value="2">Opção 3</option>
<option value="3">Opção 3</option>
</select>
<label>Filtro</label>
</div>
<div class="switch col s2 l2">
<div class="switch">
<label>
Não
<input type="checkbox">
<span class="lever"></span>
Sim
</label>
</div>
</div>
</div><!-- /row -->
</form>
JS
$(document).ready(function () {
$(".switch").find("input[type=checkbox]").on("change",function() {
var filtro = $(this).closest("input[type=checkbox]").prop('checked');
if(filtro == true) {
alert("true");
//$(this).closest('select').prop('disabled', true);
} else {
alert("false");
//$(this).closest('select').prop('disabled', false);
}
});
});
I can already get the value of the Switch to know when to enable select
and when to disable it, but I can not find the closest select
to change its state.
There are several% w / w% I need to do this, so finding the nearest Switch and changing its value is essential.
Thank you in advance.