Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Veronica Burd 76 posts 201 karma points
    Sep 15, 2014 @ 13:17
    Veronica Burd
    0

    Custom Property Editor - Get value of MultiNodeTreePicker

    Hi All,

    I'm trying to create a custom property editor that will return all child documents of a given parent for a given document type. I've found examples of how to setup something similar here: Umbraco v7 XPathDropdownList aka Docr

    My problem has to be read from a separate control.  To this end I set up my custom control to require the document type alias and the alias of the control that holds the document to be used as parent. I've found that if this control is of type MultiNodeTreePicker then I can't read it's value.  Textstring and number fields, however, work fine.

    Can anyone see what I'm doing wrong here?

    Thanks

    Ver

    Controller file:

    angular.module("umbraco")
        .controller("cmsHoR.DocrController",
        function ($scope, docrResource, notificationsService, editorState) {
    
            //first we retrieve all children docs from requested node
            docrResource.getChildren($scope.model.config.documentTypeAlias,
                                     editorState.current,
                                     $scope.model.config.fieldToRead).then(function (response) {
    
                $scope.documents = response.data;
            }, function () {
                notificationsService.error("Error", "Error loading child documents");
            });
    
    });

    Resources File

     angular.module('umbraco.resources').factory('docrResource', function ($q, $http) {
         return {
    
            getChildren: function (documentTypeAlias, currentState, fieldToRead) {
                if (currentState != undefined && documentTypeAlias != "") {
    
                    //Urggghh.. currently hardcoding path to property
                    var rootNode = currentState.tabs[0].properties[7];
    
                    var url = "backoffice/cmsHoR/DocrApi/GetChildDocuments";
                    url += "?documentAlias=" + documentTypeAlias;
                    url += "&rootNode=" + rootNode.value;
    
                    return request = $http.get(url);
                }
    
                return null;
            }
         };
    
     });

    View file:

    <div ng-controller="cmsHoR.DocrController">
        <select 
            name="DocrDropdownList" 
            class="umb-editor umb-dropdown" 
            ng-model="model.value" 
            ng-options="d.Id as d.Name for d in documents" />
    
    </div>

    Manifest

    {
      propertyEditors:
      [
        {
          alias: "cmsHoR.Docr",
          name: "cmsHoR Document Selection",
          editor:
          {
            view: "~/App_Plugins/Docr/Docr.html"
          },
          prevalues: 
          {
            fields: 
        [
          { 
            label: "Document Type Alias",
            description: "Type the document alias to select",
            key: "documentTypeAlias",
            view: "textstring"
          },
          { 
            label: "Alias of field to use as parent",
            description: "Type the alias of a content picker field to be used as the parent document",
            key: "fieldToRead",
            view: "textstring"
          }
        ]
         }
        } 
      ],
      javascript: 
      [
        "~/App_Plugins/Docr/Docr.controller.js",
        "~/App_Plugins/Docr/Docr.resources.js",
      ]
    }

    Chrome debug showing contents of MultiNodeTreePicker via editorState.current

    Chrome debug showing contents of text field via editorState.current

    Document showing that Link To Sitting has a value

  • Veronica Burd 76 posts 201 karma points
    Sep 16, 2014 @ 13:16
    Veronica Burd
    1

    Hi All,

    On further investigation I found that this only happens if I try to give a maximum value to the picker.  Without it, the value is correctly shown in editorState.current.tabs[x].properties[y].

    BTW, I found that using the contentEditingHelper provides 'easier' access to the editorState properties:

    contentEditingHelper.getAllProps(editorState.current)

    This gives me a flat array of objects which I can then use to match according to the alias I require.  Much simpler for me than trying to recurse through all entries or much worse, hardcoding the path.

    Regards

    ** edited to correct brackets as per Kristian's post below.

     

  • Veronica Burd 76 posts 201 karma points
    Sep 17, 2014 @ 08:02
    Veronica Burd
    0

    Further update,  I've worked around my problem by sitting using a nuPicker XML Dropdownlist as the separate control and setting it to store data as CSV.  This control works correctly with editorState.

    My last issue is how to determine when a user selects a different value in the dropdown as I then need to change the data in my custom control accordingly.

    Ver

  • kristian schneider 190 posts 351 karma points
    Sep 19, 2014 @ 11:43
    kristian schneider
    0

    Just a side note to anyone landing here for the same reason as me. 

    The syntax to get the properties is:

    contentEditingHelper.getAllProps(editorState.current)

    not square brackets. 

    Thats all.

  • Veronica Burd 76 posts 201 karma points
    Sep 19, 2014 @ 11:56
    Veronica Burd
    0

    Hmm.  Using the nuPicker solved my original MNTP issue but gave me another.  I've found that the nuPicker XML Dropdown does not populate itself upon creating a document.  I need to save the document first, which is a pain since I really need the MNTP/nuPicker dropdown to be mandatory.

    I'll raise an issue against umbraco for the MNTP.

    Ver

     


  • Luke 110 posts 256 karma points
    May 07, 2015 @ 23:44
    Luke
    0

    Hi,

    I know this is an old post but when using

    contentEditingHelper.getAllProps(editorState.current)
    

    what is the quickest way to retrieve the property you want with the alias? For example I want to retrieve the property with alias newsTitle

    Regards, L

  • Marc Ferrold 24 posts 105 karma points
    Jul 09, 2015 @ 06:13
    Marc Ferrold
    0

    Hello, hi, g'day

    A little late to the party, maybe, but I thought I'd share my findings, having dealt with a similar issue:

    contentResource.getById($scope.control.value.id).then(function (content) {                        
                        var props = contentEditingHelper.getAllProps(content);
                        for(i = 0; i < props.length; i++)
                        {                            
                            if(props[i].alias === "image")
                            {
                                $scope.control.value.product = {};
                                $scope.control.value.product.name = $scope.control.value.name;
                                $scope.control.value.product.imgId = productProps[i].value;                                
                            }
                        }
                    });
    

    This will find a node with a given ID (can of course also use the "current" suggestions above), and loops the properties and looks for an alias of a given string (here: "image"). This way you can look for a property of a given name. This looks/feels a little messy, but it works and I was under a bit of pressure while making it :D

    Hope this helps someone

Please Sign in or register to post replies

Write your reply to:

Draft