Reputation: 221
I ran into a headache situation. When I checked the selection option (05/30/2012 EQ), I can't click select button to submit the action, but I am supposed to be able to click it. The issue happens with Chrome and I.E, but it is good with FF. I think it is a Jquery incompatibility issue. I attached some of my code as follows:
function $recalcSelection($checkbox) {
$selectActionList.find("option").each(function() {
$optionLength = $table.find("td.actioncolumn input:checked").length;
if($optionLength <= 0) {
$(this).attr("disabled", true);
} else if($optionLength == 1) {
$(this).attr("disabled", false);
} else {
if(
$(this).val() == "editAppointment" ||
$(this).val() == "copyAppointment" ||
$(this).val() == "viewShowList" ||
$(this).val() == "viewScheduledTimes")
{
$(this).attr("disabled", true);
} else {
$(this).attr("disabled", false);
}
}
});
if($selectActionList.find("option:selected").attr('disabled')) {
$selectActionList.find("option:enabled").eq(0).attr("selected", true);
}
if($selectActionList.find("option:enabled").length <= 0) {
$selectActionButton.attr("disabled", true);
} else {
$selectActionButton.attr("disabled", false);
}
}
$selectActionButton is the submit button, and $selectactionlist is the select list. I tried to print ($selectActionList.find("option:enabled").length in Chrome, it is 0. But when I was printing it in FF, it is 7. Can anyone help me to figure out why? I would so appreciate it. thanks
I attached some of the HTML table as follows:
<table id="appointmentTable">
<thead>
<tr class="headerrow">
<th class="actioncolumn"></th>
<th class="datecolumn">Date</th>
<th class="earliesttimecolumn">Start Time</th>
<th class="clientnamecolumn">Client</th>
<th class="locationcolumn">Location</th>
<th class="roomcolumn">Rooms</th>
<th class="typecolumn">Type</th>
<th class="filledtimescolumn">Filled Times</th>
</tr>
</thead>
<tbody>
<tr class=" hiddenrow" appointmentid="15166">
<td class="actioncolumn"><input type="checkbox" name="appointmentids[]" value="15166" /></td>
<td class="datecolumn"><span title="1338094800"></span><a href="?action=viewDailyUsers&date=05/27/2012&clients[]=8" title="View Appointments on 05/27/2012">05/27/2012</a></td>
<td class="earliesttimecolumn"></td>
<td class="clientnamecolumn">CPH</td>
<td class="locationcolumn">New Location</td>
<td class="roomcolumn"></td>
<td class="typecolumn">Screening</td>
<td class="filledtimescolumn">0/0</td>
</tr>
</tbody>
<tfoot>
<tr class="actionrow">
<td colspan="2" class="actioncolumn"></td>
<td colspan="6">With Selected:</td>
</tr>
<tr class="actionrow">
<td colspan="2" class="actioncolumn">
<input type="submit" name="button" value="Create New" />
</td>
<td colspan="6">
<select id="selectactionlist" name="selectaction">
<optgroup label="Adjustments">
<option value="editAppointment">Edit</option>
<option value="copyAppointment">Copy</option>
<option value="deleteAppointment">Delete</option>
</optgroup>
<optgroup label="Lists">
<option value="viewShowList">Show/No Show List</option>
<option value="viewScheduledTimes">Schedule List</option>
</optgroup>
<optgroup label="Hidden">
<option value="hideAppointment">Hide</option>
<option value="showAppointment">Show</option>
</optgroup>
</select>
<input id="selectactionbutton" type="submit" name="button" value="Select" />
</td>
</tr>
</tfoot>
Upvotes: 1
Views: 740
Reputation: 56429
Instead of doing the following:
if (foo) {
$(this).attr("disabled", true);
} else {
$(this).attr("disabled", false);
}
You should add and remove the disabled attribute, as sometimes just the presence of the disabled attribute can make it disabled (probably why chrome keeps it disabled). Try this instead:
if (foo) {
$(this).attr("disabled", true);
} else {
$(this).removeAttr("disabled");
}
EDIT: Try this exact code
function $recalcSelection($checkbox) {
$selectActionList.find("option").each(function() {
$optionLength = $table.find("td.actioncolumn input:checked").length;
if($optionLength <= 0) {
$(this).attr("disabled", true);
} else if($optionLength == 1) {
$(this).removeAttr("disabled");
} else {
if($(this).val() == "editAppointment" ||
$(this).val() == "copyAppointment" ||
$(this).val() == "viewShowList" ||
$(this).val() == "viewScheduledTimes")
{
$(this).attr("disabled", true);
} else {
$(this).removeAttr("disabled");
}
}
});
if($selectActionList.find("option:selected").attr('disabled') != "true") {
$selectActionList.find("option").filter(function () { return $(this).attr("disabled") != null}).eq(0).attr("selected", true);
}
if($selectActionList.find("option").filter(function () { return $(this).attr("disabled") != null}).length <= 0) {
$selectActionButton.attr("disabled", true);
} else {
$selectActionButton.removeAttr("disabled");
}
}
Upvotes: 1