Copied to clipboard

Flag this post as spam?

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


  • Ben McKean 272 posts 549 karma points
    Mar 09, 2016 @ 14:36
    Ben McKean
    0

    Colorpicker custom property type

    I'm trying to create a custom property type that uses the built in property type for the Umbraco color picker but not having much luck!

    I'm a bit of an Angular noob so forgive me if I'm missing something obvious!

    I've had a look at the Umbraco source to get the HTML for the view and the code for the controller and created them in files in UIMatic\backoffice\views as colorpicker.html and colorpicker.controller.js. Both of these files get called but I'm getting console errors when I use them. Code for the HTML file is (copied from Umbraco source)

    <div ng-controller="UIOMatic.Views.ColorPickerController">
    
    <div ng-if="!isConfigured">
        <localize key="colorpicker_noColors">You haven't defined any colors</localize>
    </div>
    
    <ul class="thumbnails color-picker">
        <li ng-repeat="(key, val) in property.config.items" ng-class="{active: property.value === val}">
            <a ng-click="toggleItem(val)" class="thumbnail" hex-bg-color="{{val}}">
    
            </a>
        </li>
    </ul>
    

    Code for controller is :

    function ColorPickerController($scope) {
    $scope.toggleItem = function (color) {
        if ($scope.model.value == color) {
            $scope.model.value = "";
        }
        else {
            $scope.model.value = color;
        }
    };
    $scope.isConfigured = $scope.model.config && $scope.model.config.items && _.keys($scope.model.config.items).length > 0;}
    angular.module("umbraco").controller("UIOMatic.Views.ColorPickerController", ColorPickerController);
    

    However, I get the following error:

    TypeError: Cannot read property 'config' of undefined at new ColorPickerController

    and it refers to this line:

     $scope.isConfigured = $scope.model.config && $scope.model.config.items && _.keys($scope.model.config.items).length > 0;
    

    I suspect its something about not being able to get the approved color values from Umbraco but not sure where this would go.

    In my package.manifest the only thing I'm doing is referencing the colorpicker.controller.js file

    Thanks in advance

  • Comment author was deleted

    Mar 09, 2016 @ 15:03

    Yeah your color pickers needs config (you need to define the colors) so in your package manifest you'll also need to setup those

  • Ben McKean 272 posts 549 karma points
    Mar 09, 2016 @ 15:05
    Ben McKean
    0

    Thanks Tim, could you point me in the direction of example where I can do that? I'd like it to get the colors from the approved colors in Umbraco

  • Comment author was deleted

    Mar 09, 2016 @ 15:18

    Some details here https://our.umbraco.org/documentation/tutorials/Creating-a-Property-Editor/part-2 you'll have to update the package.manifest

    There is probably a built in view you can point it to, check the umbraco\Views\propertyeditors\colorpicker directory

  • Ben McKean 272 posts 549 karma points
    Mar 09, 2016 @ 15:43
    Ben McKean
    0

    Sorry Tim, maybe I am misunderstanding but I don't actually need to create a new property type editor. I just need to use the built in Umbraco one that is located here /umbraco/Views/propertyeditors/colorpicker/colorpicker.html

    and then save and retrieve the values from the UI-O-Matic screen.

    Is this possible?

    I've tried the following but still get the config error:

    [UIOMaticField("Color", "", View = "~/umbraco/Views/propertyeditors/colorpicker/colorpicker.html")]
    public string Color { get; set; }
    
  • Comment author was deleted

    Mar 09, 2016 @ 15:47

    Ah I see well then you would need to wrap it in a custom UI-O-Matic property view,

    These 2 link should get you started http://uiomatic.readthedocs.org/en/latest/04.CustomPropertyViews/

    http://www.enkelmedia.se/blogg/2013/12/4/umbraco-7-use-the-rich-text-editor-tinymce-in-a-custom-section.aspx

Please Sign in or register to post replies

Write your reply to:

Draft