I'm having problems with updating from a list of checkboxes. The application displays a list of data in which one of the columns is a list of checkboxes used to update a flag in the table. The requirement is that the user can select all of the checkboxes displayed, deselect all of the checkboxes displayed, select individual boxes, or select all/select none and them go back and select/deselect specific ones; all followed by selecting update and saving the changes.
This application is working fine when the user selects all and updates, selects none and updates, or selects individual boxes and updates.
But when they try to do a select all or select none, then go back and select of deselect a one or more boxes and then select updates, the individual selections are lost and only the mass selection is saved.
I inherited this code and am new to Grails. I've spent two days debugging this and searching the web but still cannot see what is wrong. It just seems to ignore the individual changes once the mass selection is made and I can't see why.
Any help to explain what is going wrong would be greatly appreciated!
The code for generating the list with the checkboxes:
The code for the update, select all, and select none controls:
The related javascript functions:
The groovy controller method:
This application is working fine when the user selects all and updates, selects none and updates, or selects individual boxes and updates.
But when they try to do a select all or select none, then go back and select of deselect a one or more boxes and then select updates, the individual selections are lost and only the mass selection is saved.
I inherited this code and am new to Grails. I've spent two days debugging this and searching the web but still cannot see what is wrong. It just seems to ignore the individual changes once the mass selection is made and I can't see why.
Any help to explain what is going wrong would be greatly appreciated!
The code for generating the list with the checkboxes:
Code:
<g:each in="${feedbackProfileDataList}" status="i" var="feedbackProfileDataList">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
.
.
.
<td style="text-align: right">
<input type="hidden" name="isSpamCheckbox" id="spamCheckbox_${i}" value="${feedbackProfileDataList.id}_${(feedbackProfileDataList.content?.spamFlag == null) || (feedbackProfileDataList.content?.spamFlag == false) ? 'null' : feedbackProfileDataList.content?.spamFlag}"/>
<g:if test="${feedbackProfileDataList.content?.spamFlag}">
<input onclick="setCheckboxValue(this, 'spamCheckbox_${i}', '${feedbackProfileDataList.id}', 'null')" type="checkbox" checked="checked"/>
</g:if>
<g:else>
<input onclick="setCheckboxValue(this, 'spamCheckbox_${i}', '${feedbackProfileDataList.id}', 'true')" type="checkbox"/>
</g:else>
</td>
</tr>
</g:each>
Code:
<div class="buttons" style="margin-bottom:5px;">
<span class="button colR"><g:actionSubmit class="save" action="listUpdate" value="Update" /></span>
<span class="clearFloat"></span>
<div class="colR" style="margin: 4px 0px 0px 0px;">
Select All: <input type="radio" name="selectCheckboxes" onclick="selectAll();" style="margin-right: 10px; height:12px;"/>
Select None: <input type="radio" name="selectCheckboxes" onclick="selectNone();" style="margin-right: 7px; height:12px;"/>
</div>
<span class="clearFloat"></span>
</div>
Code:
function selectAll()
{
jQuery("input:checkbox").each(function()
{
if(jQuery(this).attr("checked") == true)
{
//If Selected, Unselect
jQuery(this).attr("checked","checked");
}
else
{
//If Unselected, Select
jQuery(this).click();
jQuery(this).attr("checked","checked");
}
});
}
function selectNone()
{
jQuery("input:checkbox").each(function()
{
if(jQuery(this).attr("checked") == false)
{
//If Unselected, Select
jQuery(this).removeAttr("checked");
}
else
{
//If Selected, Unselect
jQuery(this).click();
jQuery(this).removeAttr("checked");
}
});
}
function setCheckboxValue(element, hiddenInput, recordId, isChecked)
{
jQuery("#"+hiddenInput).val(recordId+"_"+isChecked);
}
function selectedRadio(radiogroup)
{
for(i=0;i<radiogroup.length;i++)
{
if(radiogroup[i].checked)
{
return radiogroup[i].value;
}
}
return null;
}
Code:
def listUpdate = {
System.out.println "In listUpdate"
if(params.isSpamCheckbox)
{
def checkboxes = []
params.isSpamCheckbox.each
{
checkboxes << it.replaceAll("\\s", "")
}
if(checkboxes.size > 0)
{
checkboxes.each
{
System.out.println it
def values = it.split("_")
def feedbackProfile = MtFeedbackProfile.get(values[0].toInteger())
if(feedbackProfile)
{
if(values[1] != "null")
{
feedbackProfile.spamFlag = new Boolean(values[1])
}
else
{
feedbackProfile.spamFlag = null
}
}
}
}
}
redirect(action:listSpam,
params:["spamFilters":params.spamFilters,
"areDuplicatesExcluded":params.areDuplicatesExcluded,
"withoutComments":params.withoutComments,
"filterComments":params.filterComments,
"filterOID":params.filterOID,
"startDate":params.startDate,
"endDate":params.endDate,
"email":params.email])
}