How to enable current parent on uncheck?

How to enable parent after on last child uncheck?

  • I have implemented code for enable/disable childs and parents based on user requirement so one of the requirement I have kendo treeview with checkboxes where i implemented below code when child is uncheck enable parent thats what it suppose to do but problem is if i check multiple childs and uncheck any one of them its enabling parent. I want to enable parent when last child gets unchecked. see code below so far... HTML <div id="treeViewDisplay4" class="dropdown-menu multi-level" ng-style="nonPersistentProcess.geoLocationStyle"> <div kendo-tree-view="geoLocationTree" k-data-source="geoLocationDataSource" options="geoLocationTreeOptions" k-on-expand="onGeoExpand(kendoEvent)" k-rebind="nonPersistentProcess.selectedTypeGEO"></div> </div> index.js $scope.updateGeoLoctionList = function(geoLocation){ var pos = $.inArray(geoLocation.text, selectedGeoLocations); if(pos < 0){ selectedGeoLocations.push(geoLocation.text); selectedGeoLocationIds.push(geoLocation.id); //if Global is checked disable all parent and children if (geoLocation.id === 5657){ $.each(geoLocation.parent(),function(index,location) { if (location.id !== geoLocation.id) { $.each(location._childrenOptions.data.items,function(index,child){ var disableChildId = 'disabled' + child.id; var model = $parse(disableChildId); model.assign($scope, true); }) var disableItemId = 'disabled' + location.id; // Get the model var model = $parse(disableItemId); // Assigns a value to it model.assign($scope, true); } }); } // If a child is checked Disable the parents try { var parent = geoLocation.parent().parent(); var disableParentId = 'disabled' + parent.id; var parentModel = $parse(disableParentId); parentModel.assign($scope, true); } catch (err) { // Ignore since this happens when a node is selected which has no children } //Expand tree on parent check so childs can be disabled. $scope.geoLocationTree.expand($scope.geoLocationTree.findByText(geoLocation.text)); //If the parent item is checked, disable all the children if(geoLocation.items) { $.each(geoLocation.items,function(index,location) { var disableItemId = 'disabled' + location.id; // Get the model var model = $parse(disableItemId); // Assigns a value to it model.assign($scope, true); }); } } else { selectedGeoLocations.splice(pos,1); selectedGeoLocationIds.splice($.inArray(geoLocation.id,selectedGeoLocationIds),1); //if Global is uncheck enable all parents and children if (geoLocation.id === 5657){ var getParent = geoLocation.parent(); $.each(geoLocation.parent(),function(index,location) { if (location.id !== geoLocation.id) { $.each(location._childrenOptions.data.items,function(index,child){ var disableChildId = 'disabled' + child.id; var model = $parse(disableChildId); model.assign($scope, false); }) var disableItemId = 'disabled' + location.id; // Get the model var model = $parse(disableItemId); // Assigns a value to it model.assign($scope, false); } }); } // If child is unchecked Enable the parent try { var parent = geoLocation.parent().parent(); $.each(parent._childrenOptions.data.items,function(index,childNode){ for(var i=0; i < geoLocation.length; i++){ } }) var disableParentId = 'disabled' + parent.id; // Get the model var parentModel = $parse(disableParentId); // Assigns a value to it parentModel.assign($scope, false); } catch (err) { // Ignore since this happens when a node is selected which has no children } //If the parent item is unchecked, enable the childrens if(geoLocation.items){ $.each(geoLocation.items,function(index,location){ var disableItemId = 'disabled' + location.id; // Get the model var model = $parse(disableItemId); // Assigns a value to it model.assign($scope, false); }); } } $scope.nonPersistentProcess.geoLocations = selectedGeoLocations.toString(); }; Config.js geoLocationTreeConfig : { template: '{{dataItem.text}}', checkboxes: { checkChildren: false, template: '<input ng-disabled=\'disabled#: item.id #\' type=\'checkbox\' ng-click=\'updateGeoLoctionList(dataItem)\' value=\'true\' />' }

  • Answer:

    I passed selectedItems[ ] to newArray and with if condition i was able to enable parent after last child uncheck. try { var parent = geoLocation.parent().parent(); var checkedChildrens = []; for (var i=0; i<selectedRiskGeoLocations.length; i++){ var checkNodes = selectedRiskGeoLocations[i]; checkedChildrens.push(checkNodes); } if (checkedChildrens.length === 0){ var disableParentId = 'disabled' + parent.id; // Get the model var parentModel = $parse(disableParentId); // Assigns a value to it parentModel.assign($scope, false); }; }

aftab at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.