umbraco-doc-type-grid-editor
umbraco-doc-type-grid-editor copied to clipboard
Cannot read properties of undefined (reading 'allowedDocTypes')
If we have a NestedContent element with a grid inside of it and the NestedContent section is open and there is a DocTypeGridEditor element inside the grid and then Save the Document and after that try to click on the DocTypeGridEditor element. Then we get this error:
TypeError: Cannot read properties of undefined (reading 'allowedDocTypes')
at Scope.$scope.setDocType (doctypegrideditor.controllers.js?cdv=752043050:85)
at fn (eval at compile (angular.js?cdv=752043050:16548), <anonymous>:4:150)
at callback (angular.js?cdv=752043050:29123)
at Scope.$eval (angular.js?cdv=752043050:19523)
at Scope.$apply (angular.js?cdv=752043050:19622)
at HTMLDivElement.<anonymous> (angular.js?cdv=752043050:29127)
at HTMLDivElement.dispatch (jquery.min.js?cdv=752043050:2)
at HTMLDivElement.v.handle (jquery.min.js?cdv=752043050:2)
This is doctypegrideditor.controllers.js at line 85 inside the Our.Umbraco.DocTypeGridEditor.GridEditors.DocTypeGridEditor
That's error comes because the $scope.control.editor.config is null.
If we then close the NestedContent section and Save the Document, and after that try to click on the DocTypeGridEditor element. we get no errors. So it only occurs when we have the NestedContent open while saving.
We can omit the error by checking if the overlayOptions editorName or allowedDocTypes is set and then skip the use of $scope.control.editor.config inside the $scope.setDocType = function () {
if (!overlayOptions.editorName) {
overlayOptions.editorName = $scope.control.editor.name;
overlayOptions.allowedDocTypes = $scope.control.editor.config.allowedDocTypes || [];
overlayOptions.showDocTypeSelectAsGrid = $scope.control.editor.config.showDocTypeSelectAsGrid === true;
overlayOptions.nameTemplate = $scope.control.editor.config.nameTemplate;
overlayOptions.size = $scope.control.editor.config.largeDialog ? null : $scope.control.editor.config.overlaySize || "small";
}
What happens if you try to add a new block then? If you set allowedDocTypes to empty, I'd guess you won't be able to select a doctype?
What happens if you try to add a new block then? If you set allowedDocTypes to empty, I'd guess you won't be able to select a doctype?
If i havent clicked on the plugin to initiate $scope.setDocType before i save, then it will fail, because then the overlayOptions.editorName aint set.
If i then set the allowedDocTypes to be empty if the $scope.control.editor.config is undefined or null, then it works either way and i can select a doctype.
if (!$scope.control.editor.config) {
$scope.control.editor.config = {
allowedDocTypes: []
};
}
overlayOptions.editorName = $scope.control.editor.name;
overlayOptions.allowedDocTypes = $scope.control.editor.config.allowedDocTypes || [];
overlayOptions.showDocTypeSelectAsGrid = $scope.control.editor.config.showDocTypeSelectAsGrid === true;
overlayOptions.nameTemplate = $scope.control.editor.config.nameTemplate;
overlayOptions.size = $scope.control.editor.config.largeDialog ? null : $scope.control.editor.config.overlaySize || "small";
works either way
What i meant by that, is that its working even if you havent clicked on the exisisting plugin before you save and then click on a new block.
I can see i havent mentioned that this error with Cannot read properties of undefined (reading 'allowedDocTypes') only occurs if you (Save). Its working fine when you (Save and publish).
if (!$scope.control.editor.config) { $scope.control.editor.config = { allowedDocTypes: [] }; }
The only issue now is that the view does not update as it should. So this is only half a solution :)