Angulat JS Conditional display of CUSTOM FIELDS
--------------------------------------------------------------------------
Angular JS Part:
------------------------
$scope.selectedCustomFieldValuesMap={};
$scope.selectedCustomFieldDefIds=[];
$scope.showHideWorkerFollowOn = function(selectedCustFieldDefId,selectedValue){
if(selectedValue != 'Select'){
if(!$scope.selectedCustomFieldDefIds.includes(selectedCustFieldDefId)){
$scope.selectedCustomFieldDefIds.push(selectedCustFieldDefId);
}
$scope.selectedCustomFieldValuesMap[selectedCustFieldDefId] = selectedValue;
angular.forEach($scope.reqResumeInfo.customFields, function(customField) {
if(selectedCustFieldDefId ==customField.parentCustomFieldDefId && customField.followOnFor !=selectedValue){
remove(selectedCustFieldDefId);
}
});
}else{
removeFromArray($scope.selectedCustomFieldDefIds,selectedCustFieldDefId);
$scope.selectedCustomFieldValuesMap[selectedCustFieldDefId] = '';
}
};
$scope.customIncludes = function(container,value){
var returnValue = false;
var pos = container.indexOf(value);
if (pos >= 0) {
returnValue = true;
}
return returnValue;
};
function removeFromArray(selectedCustomFieldDefIds,selectedCustFieldDefId) {
var index = selectedCustomFieldDefIds.indexOf(selectedCustFieldDefId);
if(index >-1)
selectedCustomFieldDefIds.splice(index,1);
}
function remove(selectedCustFieldDefId){
angular.forEach($scope.reqResumeInfo.customFields, function(customField) {
if(selectedCustFieldDefId ==customField.parentCustomFieldDefId){
removeFromArray($scope.selectedCustomFieldDefIds,selectedCustFieldDefId);
selectedCustFieldDefId=customField.customFieldDefId;
customField.value=null;
$scope.selectedCustomFieldValuesMap[selectedCustFieldDefId] = '';
}
});
}
JSP Part:
class="row m-t-sm" ng-if="reqResumeInfo.customFields.length > 0" ng-repeat="customField in reqResumeInfo.customFields track by $index" ng-init="$customFieldIndex = $index">
ng-if="customField.parentCustomFieldDefId == 0 || (selectedCustomFieldDefIds.includes(customField.parentCustomFieldDefId) && customField.followOnFor == selectedCustomFieldValuesMap[customField.parentCustomFieldDefId])"