Copied to clipboard

Flag this post as spam?

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


  • Zakhar 171 posts 397 karma points
    Feb 10, 2016 @ 13:21
    Zakhar
    0

    Umbraco 7 doesn't save my custom property value

    Hey guys,

    I've created a custom property using AngularJS as described here: http://umbraco.github.io/Belle/#/tutorials/CreatingAPropertyEditor. Currently it's a simple dropdown which will load values from database, but currently I just use static data.

    I use the last version - v7.3.7.

    I do see the values in the dropdown, but I can't make it work - the value is not saved after I press save.

    Here is my manifest

    {   
        //you can define multiple editors   
        propertyEditors: [      
            {
                alias: "My.MemberCompanyPicker", // this must be a unique alias 
                name: "Member Company Picker", // name, this will show in the backoffice 
                valueType: "STRING", // "INT", "DATETIME", "STRING" "TEXT" and "JSON"
                editor: { 
                    view: "~/App_Plugins/MemberCompanyPicker/index.html" // the html file we will load for the editor
                }
            }
        ]
        ,
        //array of files we want to inject into the application on app_start
        javascript: [
            '~/App_Plugins/MemberCompanyPicker/membercompanypicker.controller.js'
        ]
    }
    

    My html file:

    <div ng-controller="MyMemberCompanyPicker">
        <select ng-model="selected">
            <option ng-repeat="c in companies track by c.id" value="{{c.id}}">{{c.name}}</option>
        </select>
    </div>
    

    And the controller:

    (function () {
        'use strict';
    
    angular.module("umbraco")
        .controller("MyMemberCompanyPicker",
        function ($scope) {
            //var vm = this;
            $scope.selected = 'Company1';
            $scope.companies = [
                            { id: '1', name: 'Company1' },
                            { id: '2', name: 'Company2' }
            ];
        });
    
    })();
    

    I don't really understand how it's supposed to work and how Umbraco will understand which value to save. Another question is how is the saved value is going to be loaded during the next edit? Can't find the answers anywhere.

    Can someone advice please?

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Feb 10, 2016 @ 13:43
    Kevin Jump
    0

    Hi

    If everything else is working (and it sounds like it is) you need to put the value you want saving into $scope.model

    this probably just means changing $scope.selected to $scope.model in the controller and ng-model from selected to model in the html.

    Kevin

  • Zakhar 171 posts 397 karma points
    Feb 10, 2016 @ 15:14
    Zakhar
    0

    Hi Kevin,

    Thanks for reply. It makes more sense now.

    I briefly changed the property data type to textstring and updated the value. Then I changed the data type back to my custom property editor and I can see that the value is actually loaded to $scope.model.value

    I updated my select to update $scope.model.value and made sure the value is changed. However it's still not saved when I save my changes.

    What else can be missing?

    P.S. I also tried your suggestion to assign my value to $scope.model but that didn't work.

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Feb 10, 2016 @ 15:53
    Kevin Jump
    102

    Hi

    just looking at some code I have for a property editor (fairly simple one here), i noticed that in my manifest valueType is inside Editor

    editor: {
        valueType: "JSON",
        view: "~/App_Plugins/OpeningSoon/OpeningSoon.html"
    },
    

    not sure if that a typo in the documentation, but i might be worth moving that.

    i would try just setting model.value to a fixed string and see if that gets set?

    For more complex stuff you can subscribe to the formSubmitting event inside your controller, and set values then but you really shouldn't need to do that for something this simple. e.g.

    var unsubscribe = $scope.$on("formSubmitting", function (ev, args) { 
      // set something to $scope.model.value here.
    });
    
  • Zakhar 171 posts 397 karma points
    Feb 10, 2016 @ 16:53
    Zakhar
    0

    Thanks Kevin!

    Finally figured it out. My code was setting $scope.model.value, but at the same time it was resetting the model object and removing other model fields and apparently it broke something in the Umbraco workflow.

    Also worth noting that it doesn't support 'controller as' syntax.

  • Tim C 161 posts 528 karma points
    May 14, 2016 @ 06:27
    Tim C
    0

    Zakhar

    This is a long shot but I am spending far too many hours trying to get a simple custom dropdown to work.

    Mine won't save values either - can you post your final controller/view/package,manifest so I can try yours?

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft