Nibble

Advanced property editors for Umbraco v7, prevalue editors

As you could see in the 2 prop editors for Umbraco examples it’s super easy to add config options to your v7 prop editors (http://www.nibble.be/?p=330, http://www.nibble.be/?p=285)

As it mentions in the manifest docs http://umbraco.github.io/Belle/#/tutorials/manifest there is a prevalues part where you can setup your config options…

So

prevalues: {
            fields: [
                {
                    label: "Number of chars",
                    description: "Enter the number of chars to limit on",
                    key: "limit",
                    view: "requiredfield",
                    validation: [
                        {
                            type: "Required" 
                        }                        
                    ]
                }
            ]
        }

Results in

Changing the type of prevalue editor

Of course you aren’t limited to a simple text input if you take a look at the available out of the box types (found in \Umbraco\Views\prevalueeditors )

You’ll find

image

So if I want to update my matrix prop editor to have numeric prevalues (since I need to define number or rows and columns)

I just need the name of the view (and don’t need the .html)

That then becomes

            fields: [
                {
                    label: "Number of columns",
                    description: "Enter the number of columns",
                    key: "cols",
                    view: "number",
                    validation: [
                        {
                            type: "Required" 
                        }                        
                    ]
                },
                {
                    label: "Number of rows",
                    description: "Enter the number of rows",
                    key: "rows",
                    view: "number",
                    validation: [
                        {
                            type: "Required" 
                        }                        
                    ]
                },

And results in

image

Using prop editors as prevalue editors

It’s also possible to plug in custom prevalue editors, all  you need to do is point it to a view and you can use a prop editor as a prevalue editor!

So adding this

                {
                    label: "Testing",
                    description: "Test",
                    key: "test",
                    view: "~/App_Plugins/MatrixEditor/matrixeditor.html",
                    validation: [
                        {
                            type: "Required" 
                        }                        
                    ]
                }

Will make it possible to use the matrix prop editor as a prevalue editor on it’s own settings

image

Currently you’ll have to manually check in your controller if the config has values or not since it’s not possible to set default values that get passed to the prevalue editor (but should be possible soon)

2 Comments so far

  1. Jason on July 2nd, 2014

    Is there anything special that needs to be done to get the RTE working in the prevalues?

  2. Tom on March 22nd, 2017

    Is there a way to programatically add a data type to a document type in v7 and above.. we used to use:
    var ddl = new DataTypeDefinition(-1, controlGuid);
    ddl.DatabaseType = DataTypeDatabaseType.Ntext;
    ddl.Key = Guid.NewGuid();
    ddl.Name = name;

    ServiceContext.DataTypeService.Save(ddl);

    foreach (var value in preValues)
    {
    var p =
    var p = new umbraco.cms.businesslogic.datatype.PreValue(0, 0, value);
    p.DataTypeId = ddl.Id;
    p.Save();
    }

    return ddl;

    But as of v7 this has stopped working..

Leave a Reply