Copied to clipboard

Flag this post as spam?

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


  • Michele 10 posts 90 karma points
    Nov 10, 2017 @ 15:41
    Michele
    0

    Approved Color property editor in a Macro

    Hi, I have a requirement to insert some content blocks with a specific look and feel into page content. The content block can have different background colors from an authorized list.

    A partial macro was the first thing that came into my mind, and the color picker is absolutely the kind of property editor I need for my macro. Unfortunately the color picker is not one of the allowed property editors so my question is: do I really have to create the custom property editor by duplicating the code for the default color picker? Really there is no other way to do this?

    Thanks, M

  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    Nov 12, 2017 @ 11:01
    Marc Goodson
    102

    Hi Michele

    Kind of!

    The thing that determines whether a particular property editor can be used as a macro parameter editor, is just a flag in it's package.manifest definition ...

    isParameterEditor: true

    So you don't need to recreate the entire editor again, instead create a new folder in app_data for your 'SuperMacroEnabledColourPicker' and within that folder create a package.manifest file

    propertyEditors: [ { alias: "SuperMacroEnabledColourPicker", name: "Super Macro Enabled Colour Picker", isParameterEditor: true, editor: { view: "~/path to the existing view for the approved colour picker" }, defaultConfig { configPropertyAlias: "defaultConfigValue"} } ]

    When you restart Umbraco it will find this new definition of the Colour Picker, and you will be able to use it as a Macro Parameter, it should function exactly like the existing Colour Picker, because it's using the same view...

    You can send the additional configuration that you would normally make via the DataType ui via the 'defaultConfig' option.

    regards

    Marc

    (but yes being able to use a 'Data Type' as a Macro Parameter editor would make life easier)

  • Michele 10 posts 90 karma points
    Nov 13, 2017 @ 10:25
    Michele
    0

    Hi Mark, I managed to get things working, my necessity was a color picker for a content block so I had to do a little bit of debugging to find that the defaultConfig had to be populated with an object called items containing a list of pairs id/color. Thanks for your help! Michele

  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    Nov 13, 2017 @ 12:55
    Marc Goodson
    0

    Yep it's hard to work out what's exactly required for that defaultConfig, working back from the Data Type UI.

    But ace you got it working!

  • Steve Milligan 11 posts 77 karma points
    Nov 22, 2017 @ 22:59
    Steve Milligan
    0

    Hi Michele

    Did you set up the defaultConfig colors in the package.manifest file? If so, can you give me an example please?

    Thanks

    Steve

  • Steve Milligan 11 posts 77 karma points
    Nov 23, 2017 @ 14:39
    Steve Milligan
    0

    I've worked out how to set up the defaultConfig colors:

    { propertyEditors: [ { alias: "ColorPicker", name: "Macro Color Picker", isParameterEditor: true, editor: { view: "~/Umbraco/Views/propertyeditors/colorpicker/colorpicker.html" }, defaultConfig:{ items: [ "FFFFFF", "000000", "43695b", etc.... ] } } ] }

  • Qaisar 31 posts 77 karma points
    Jun 20, 2019 @ 21:48
    Qaisar
    0

    Hi, I am trying to do the same thing. I have used Steve code in Umbraco V8 but it doesn't show any colors instead it says "You have not configured any approved colours". Any Ideas?

    Thanks Qaisar

Please Sign in or register to post replies

Write your reply to:

Draft