The code below can be any number, at the moment this is replicated 16 times, and inside each of the divs there a checkbox and 2 drop-downs. I have had a go at this with Paul but I have changed it and simplifying, so this is part 2, so a new thread.
<div class="card" id="modulesWrapper">
@for (int i = 0; i < Model.PropertyModuleModels.Count; i++)
{
<div class="moduleElement" data-module-id="68">
<input class="moduleEnabledCheckbox check-box" id="PropertyModuleModels_[i]__IsActive">
<select class="moduleFrequencyDropdown" id="PropertyModuleModels_[i]__FrequencyId">
<option value=""></option>
<option value="1">Monthly</option>
<option value="2">Every 2 Months</option>
<option value="3">Quarterly</option>
<option value="4">Twice a Year</option>
<option value="5">Annually</option>
</select>
<select class="moduleStartMonthDropdown" id="PropertyModuleModels_[i]__StartMonthId">
<option value=""></option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</div>
}
</div>
I then have the following jquery find() to check if any of the checkboxes have been selected and this works fine, it runs through all the divs looking to see if there at least one.
var greenTickModule = $("#modulesWrapper").find('.moduleElement input[type=checkbox]:checked');
This works well, and when there is at least 1 I show a tick as below,and its always being checked as a called function when someone closes up a card.
if (greenTickModule.length > 0) {
$("#modulesWrapper").find('.greenTick').show();
} else {
$("#modulesWrapper").find('.greenTick').hide();
}
All good so far, but what I now need to do is change the find so it also incorportaes the 2 dropdowns and see if they have a value greater than zero, as in something positive has been selected in both dropdowns.
So can I use the find below, to check each .moduleElement within #modulesWrapper and see if there exists a checkbox that has been checked and both drop-downs have a value greater than zero. My thinking is that I extend the find after the input :checked, but Iām predicting this isnāt going to be possible.
var greenTickModule = $("#modulesWrapper").find('.moduleElement input[type=checkbox]:checked');
if (greenTickModule.length > 0) {
$("#modulesWrapper").find('.greenTick').show();
} else {
$("#modulesWrapper").find('.greenTick').hide();
}
Just throwing it out there, but is something like this possible
var greenTickModule = $("#modulesWrapper").find('.moduleElement input[type=checkbox]:checked' && '.moduleElement .moduleFrequencyDropdown > option[value!=""]' && '.moduleElement .moduleStartMonthDropdown > option[value!=""]');