需要一些帮助,我有一个发行与t:selectBooleanCheck和javascript。我有几个复选框,这些复选框在某些条件下是可见的,所有这些复选框都调用javascript方法来禁用和启用页面上的按钮。
我已经将其中一个复选框移到它自己的列中,以便更好地显示。由于我移动了复选框,javascript方法无法将其识别为set复选框的一部分。我相信这是JSF提供的功能。
myPage.jspx
function checkBoxSelectedCountIgnoreId(collection, ignoreId) {
count = 0;
for (i = 0; i < collection.length; i++) {
elem = collection[i];
if (elem == null) {
break;
}else if (elem.checked && elem.id == ignoreId) {
//dont count ignoreId in checkbox checked count
}else if (elem.checked) {
count++;
}
}
return count;
}
function manageCommandButtons(checkbox) {
parentTD = checkbox.parentNode;
parentTR = parentTD.parentNode;
parentTBODY = parentTR.parentNode;
checkBoxCollection = parentTBODY.getElementsByTagName("input");
var printBtn = "printBtn";
var printIpadBtn = "printIpadBtn";
var emailBtn = "emailBtn";
var formId = checkbox.form.name;
var checkBoxCount = checkBoxSelectedCountIgnoreId(checkBoxCollection,"summaryFrm:shuttleIncluded");
/*
* disabling email button for now, always.
*/
if (checkBoxCount == 1) {
disableObject(formId, printBtn, false);
disableObject(formId, printIpadBtn, false);
disableObject(formId, emailBtn, false);
} else {
if (checkBoxCount > 1) {
disableObject(formId, printBtn, true);
disableObject(formId, printIpadBtn, true);
disableObject(formId, emailBtn, false);
} else {
disableObject(formId, printBtn, true);
disableObject(formId, printIpadBtn, true);
disableObject(formId, emailBtn, true);
}
}
}
<t:div rendered="#{quote.containerTariffQuote}" style="width: 100%">
<t:div style="float: left; width: 50%">
<t:panelGrid columns="2" >
<t:selectBooleanCheckbox id="formContainerEstimateOrderForService"
value="#{quote.forms.formContainerEstimateOrderForService}"
onclick="manageCommandButtons(this)" />
<h:outputLabel for="formContainerEstimateOrderForService"
value="#{labels['l.pages.forms.forms.containerEstimateOrderForService']} #{labels['l.pages.forms.forms.requiresOrderNumber']}" />
<t:selectBooleanCheckbox id="formContainerOnePageEstimate"
value="#{quote.forms.formContainerOnePageEstimate}"
onclick="manageCommandButtons(this)" />
<h:outputLabel for="formContainerOnePageEstimate" value="#{labels['l.pages.forms.forms.onePageEstimate']}" />
<t:selectBooleanCheckbox id="formSurveyContainer"
value="#{quote.forms.formSurvey}"
onclick="manageCommandButtons(this)" />
<h:outputLabel for="formSurveyContainer" value="#{labels['l.pages.forms.forms.survey']}" />
<t:selectBooleanCheckbox id="formCityPointeReferralAuthContainer"
value="#{quote.forms.formCityPointeReferralAuth}"
onclick="manageCommandButtons(this)"/>
<h:outputLabel for="formCityPointeReferralAuthContainer"
value="#{labels['l.pages.forms.forms.cityPointeReferralAuth']}"/>
<t:selectBooleanCheckbox id="formWorkOrderContainer"
value="#{quote.forms.formWorkOrder}"
onclick="manageCommandButtons(this)" />
<h:outputLabel for="formWorkOrderContainer" value="#{labels['l.pages.forms.forms.workOrder']}" />
</t:panelGrid>
</t:div>
<t:div style="float: right; width: 50%">
<t:panelGrid columns="2">
<t:selectBooleanCheckbox id="formContainerConfidentialWorksheet"
value="#{quote.forms.formContainerConfidentialWorksheet}"
onclick="manageCommandButtons(this)" />
<h:outputLabel for="formContainerConfidentialWorksheet"
value="#{labels['l.pages.forms.forms.confidentialWorksheet']}" />
</t:panelGrid>
</t:div>
</t:div>我希望在checkboxCollection中识别所有的复选框。
我使用tomahawk 1.1.9、richfaces 3.3和myfaces 1.2。
发布于 2015-03-04 21:27:53
因为您将它移动到它自己的面板网格中,所以选中的复选框不包括已移动的复选框,因为它现在有一个不同的parentTBODY。更正您的选择机制,以便在另一个TBODY下面检索复选框
发布于 2015-03-04 21:54:59
我就是这样修好的。
我向两个主div添加了一个styleClass属性,该属性被用作选择器。IE:<t:div id="containerQuoteSummaryForms" forceId="true" styleClass="checkBoxesSelector"....>
我还更改了javascript方法,以使用JQuery获取div中的复选框。
IE:var checkBoxCollection = jQuery(checkbox).closest('.checkBoxesSelector').find('input');
https://stackoverflow.com/questions/28773333
复制相似问题