Copied to clipboard

Flag this post as spam?

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


  • dig_nz 11 posts 60 karma points
    Jul 24, 2014 @ 15:03
    dig_nz
    0

    Custom tree property editor (ukfest-angularjs-demo) - model.value is not being updated with selected node

    Hi there,

    I am using the ukfest-angularjs-demo in my build (very helpful).

    I had to do few tweaks (file locations, paths and changes to reload the tree (http://our.umbraco.org/forum/umbraco-7/using-umbraco-7/48422-Reloading-custom-tree-problems-(UKFest-Angular-JS-Demo)

    But other than that it is all the same. I have a problem when trying to update content using the person picker property editor. The tree loads ok, and when I click a node the treeNodeSelect is being fired and also the populate() is being called. But model.value is not updated. The link 'Pick Person' remains as it is, and not showing the selected person, and when saving the content to the database no 'person' property is being set.

    The event is fired and I do get to

    $scope.submit(args.node.id);
    

    in

     $scope.dialogEventHandler.bind("treeNodeSelect", function (ev, args) {
    
    
    
            args.event.preventDefault();
    
            args.event.stopPropagation();
    
            $scope.submit(args.node.id);
    
        });
    

    and the callback populate() is being called:

     function populate(data) {
    
            $scope.model.value = data;
    
    };
    

    But model.value in the template (personpicker.html) is not being updated. I added a function that alerts for the model.vale - and it returns the correct value, but the actual template is not being updated, and also the value is not being saved to the database when saving the content.

    <div ng-controller="People.PersonPickerController">
     {{model.value}}
     <a href ng-click="getValue()">get model value</a>
     <a href ng-click="openPicker()" prevent-default>Pick person</a>
    
    </div>
    

    (getValue just alerts model.value)

    any ideas?

    Thanks!

  • dig_nz 11 posts 60 karma points
    Jul 28, 2014 @ 11:18
    dig_nz
    100

    The issue was that apply had to be called.

    The following changes to personpicker.controller.js fixed the issue for me:

    function populate(data) {
    
            $scope.safeApply($scope.setModelvalue(data));
    
        };
    
    
        $scope.setModelvalue = function (newValue) {
            $scope.model.value = newValue;
        }
    
        $scope.safeApply = function (fn) {
            var phase = this.$root.$$phase;
            if (phase == '$apply' || phase == '$digest') {
                fn();
            } else {
                this.$apply(fn);
            }
        };
    
Please Sign in or register to post replies

Write your reply to:

Draft