Conditional Display of Custom Fields using javascript:
function showHideWorkerFollowOn() {
var elements = document.getElementsByClassName("followOnFor");
for(var i = 0; i < elements.length; i++) {
var str = elements[i].id;
var ary = str.split("-");
var parentCustomFieldDefId = parseInt(ary[1]);
var customFieldDefId = parseInt(ary[2]);
if (parentCustomFieldDefId > 0 && document.getElementById("cfIndex-"+parentCustomFieldDefId)) { // only for follow on
var cfIndex = document.getElementById("cfIndex-"+parentCustomFieldDefId).value;
var cfType = document.getElementById("cfType-"+parentCustomFieldDefId).value;
var selectedValue = "";
if (cfType == 'SELECT' || cfType == 'LONG_SELECT') {
var id = "wcustomFields[" + cfIndex + "].value";
selectedValue = document.getElementById(id).value;
} else if (cfType == 'SMALL_TEXT' || cfType == 'LARGE_TEXT' || cfType == 'DRILL_DOWN') {
var id = "wcustomFields[" + cfIndex + "].value";
selectedValue = document.getElementById(id).value;
}
else if (cfType == 'RADIO') {
var el = "clientWorker.customFields[" + cfIndex + "].value";
var cfValues = document.getElementsByName(el);
for(var j = 0; j < cfValues.length; j++) {
if(cfValues[j].checked) {
selectedValue = cfValues[j].value;
}
}
} else if (cfType == 'MULTISELECT_CHECKBOX') {
var found = false;
var cfValues = document.getElementsByClassName("cfMulti-"+parentCustomFieldDefId);
for(var j = 0; j < cfValues.length; j++) {
if (cfValues[j].checked && cfValues[j].value == elements[i].value) {
showHideWorkerFollowOnLogic(customFieldDefId, elements[i].value, cfValues[j].value);
found = true;
}
}
if (!found) {
showHideWorkerFollowOnLogic(customFieldDefId, elements[i].value, "");
}
}
if (cfType != 'MULTISELECT_CHECKBOX') {
showHideWorkerFollowOnLogic(customFieldDefId, elements[i].value, selectedValue);
}
}
}
}
function showHideWorkerFollowOnLogic(customFieldDefId, elementValue, selectedValue) {
var followOnDivId = "cfRow-" + customFieldDefId;
var followOnDivValueListId = "cfRow-" + customFieldDefId+"-valueList";
var showThisFollowOn = "showThisFollowOn-" + customFieldDefId;
if (document.getElementById(followOnDivId)) {
if (elementValue == selectedValue) {
document.getElementById(followOnDivId).style.display = 'block';
document.getElementById(followOnDivValueListId).style.display = 'block';
document.getElementById(followOnDivId).removeAttribute('style');
document.getElementById(followOnDivValueListId).removeAttribute('style');
document.getElementById(showThisFollowOn).value = true;
} else {
document.getElementById(followOnDivId).style.display = 'none';
document.getElementById(followOnDivValueListId).style.display = 'none';
document.getElementById(showThisFollowOn).value = false;
var cfIndex = document.getElementById("cfIndex-"+customFieldDefId).value;
var cfType = document.getElementById("cfType-"+customFieldDefId).value;
if (cfType == 'SMALL_TEXT' || cfType == 'LARGE_TEXT' || cfType == 'DRILL_DOWN' ) {
var el = "wcustomFields[" + cfIndex + "].value";
var cfValues = document.getElementsByName(el);
for(var j = 0; j < cfValues.length; j++) {
cfValues[j].value = "";
}
} else if (cfType == 'SELECT' || cfType == 'LONG_SELECT') {
var id = "wcustomFields[" + cfIndex + "].value";
document.getElementById(id).selectedIndex = 0;
} else if (cfType == 'RADIO') {
//var el = "clientWorker.customFields[" + cfIndex + "].value";
//var cfValues = document.getElementsByName(el);
var el = "wcustomFields[" + cfIndex + "].value";
var cfValues = document.getElementsByClassName(el);
for(var j = 0; j < cfValues.length; j++) {
cfValues[j].checked = false;
}
} else if (cfType == 'MULTISELECT_CHECKBOX') {
var cfValues = document.getElementsByClassName("cfMulti-"+customFieldDefId);
for(var j = 0; j < cfValues.length; j++) {
cfValues[j].checked = false;
}
}
}
}
}
-------------
JSP:
function showHideWorkerFollowOn() {
var elements = document.getElementsByClassName("followOnFor");
for(var i = 0; i < elements.length; i++) {
var str = elements[i].id;
var ary = str.split("-");
var parentCustomFieldDefId = parseInt(ary[1]);
var customFieldDefId = parseInt(ary[2]);
if (parentCustomFieldDefId > 0 && document.getElementById("cfIndex-"+parentCustomFieldDefId)) { // only for follow on
var cfIndex = document.getElementById("cfIndex-"+parentCustomFieldDefId).value;
var cfType = document.getElementById("cfType-"+parentCustomFieldDefId).value;
var selectedValue = "";
if (cfType == 'SELECT' || cfType == 'LONG_SELECT') {
var id = "wcustomFields[" + cfIndex + "].value";
selectedValue = document.getElementById(id).value;
} else if (cfType == 'SMALL_TEXT' || cfType == 'LARGE_TEXT' || cfType == 'DRILL_DOWN') {
var id = "wcustomFields[" + cfIndex + "].value";
selectedValue = document.getElementById(id).value;
}
else if (cfType == 'RADIO') {
var el = "clientWorker.customFields[" + cfIndex + "].value";
var cfValues = document.getElementsByName(el);
for(var j = 0; j < cfValues.length; j++) {
if(cfValues[j].checked) {
selectedValue = cfValues[j].value;
}
}
} else if (cfType == 'MULTISELECT_CHECKBOX') {
var found = false;
var cfValues = document.getElementsByClassName("cfMulti-"+parentCustomFieldDefId);
for(var j = 0; j < cfValues.length; j++) {
if (cfValues[j].checked && cfValues[j].value == elements[i].value) {
showHideWorkerFollowOnLogic(customFieldDefId, elements[i].value, cfValues[j].value);
found = true;
}
}
if (!found) {
showHideWorkerFollowOnLogic(customFieldDefId, elements[i].value, "");
}
}
if (cfType != 'MULTISELECT_CHECKBOX') {
showHideWorkerFollowOnLogic(customFieldDefId, elements[i].value, selectedValue);
}
}
}
}
function showHideWorkerFollowOnLogic(customFieldDefId, elementValue, selectedValue) {
var followOnDivId = "cfRow-" + customFieldDefId;
var followOnDivValueListId = "cfRow-" + customFieldDefId+"-valueList";
var showThisFollowOn = "showThisFollowOn-" + customFieldDefId;
if (document.getElementById(followOnDivId)) {
if (elementValue == selectedValue) {
document.getElementById(followOnDivId).style.display = 'block';
document.getElementById(followOnDivValueListId).style.display = 'block';
document.getElementById(followOnDivId).removeAttribute('style');
document.getElementById(followOnDivValueListId).removeAttribute('style');
document.getElementById(showThisFollowOn).value = true;
} else {
document.getElementById(followOnDivId).style.display = 'none';
document.getElementById(followOnDivValueListId).style.display = 'none';
document.getElementById(showThisFollowOn).value = false;
var cfIndex = document.getElementById("cfIndex-"+customFieldDefId).value;
var cfType = document.getElementById("cfType-"+customFieldDefId).value;
if (cfType == 'SMALL_TEXT' || cfType == 'LARGE_TEXT' || cfType == 'DRILL_DOWN' ) {
var el = "wcustomFields[" + cfIndex + "].value";
var cfValues = document.getElementsByName(el);
for(var j = 0; j < cfValues.length; j++) {
cfValues[j].value = "";
}
} else if (cfType == 'SELECT' || cfType == 'LONG_SELECT') {
var id = "wcustomFields[" + cfIndex + "].value";
document.getElementById(id).selectedIndex = 0;
} else if (cfType == 'RADIO') {
//var el = "clientWorker.customFields[" + cfIndex + "].value";
//var cfValues = document.getElementsByName(el);
var el = "wcustomFields[" + cfIndex + "].value";
var cfValues = document.getElementsByClassName(el);
for(var j = 0; j < cfValues.length; j++) {
cfValues[j].checked = false;
}
} else if (cfType == 'MULTISELECT_CHECKBOX') {
var cfValues = document.getElementsByClassName("cfMulti-"+customFieldDefId);
for(var j = 0; j < cfValues.length; j++) {
cfValues[j].checked = false;
}
}
}
}
}
-------------
JSP:
No comments:
Post a Comment