I'd like to confirm if this is a bug or not. Perhaps I've done something wrong.
I'm building a property editor, and believe it or not this is the first time in which I've wanted to add a config (prevalues). Here's a sample of my package manifest:
{
propertyEditors: [
{
alias: "MediumEditor",
name: "Medium Editor",
(...)
prevalues: {
fields: [
{
label: "Disable Return",
description: "Enables/disables the use of the return-key.",
key: "disableReturn",
view: "boolean"
},
{
label: "Disable Double Return",
description: "Allows/disallows two (or more) empty new lines.",
key: "disableDoubleReturn",
view: "boolean"
},
{
label: "Disable Extra Spaces",
description: "When set to true, it disallows spaces at the beginning and end of the element. Also it disallows entering 2 consecutive spaces between 2 words.",
key: "disableExtraSpaces",
view: "boolean"
},
(...)
]
},
defaultConfig: {
disableReturn: "1",
disableDoubleReturn: 1,
disableExtraSpaces: true
}
}
]
}
Is my package.manifest correct?
You'll notice I tried a string, an int, and a boolean to try and set the value. None of these had an effect however.
So my property editor shows up, and I go to create a new data type. I select the new property editor I've created but none of the toggles are on. they are all off.
Looking at the request to GetPreValues in the back office, values for each editor are coming back as null. I have the following JSON result:
[
{
"label": "Disable Return",
"description": "Enables/disables the use of the return-key.",
"hideLabel": false,
"view": "boolean",
"config": {},
"key": "disableReturn",
"value": null
},
{
"label": "Disable Double Return",
"description": "Allows/disallows two (or more) empty new lines.",
"hideLabel": false,
"view": "boolean",
"config": {},
"key": "disableDoubleReturn",
"value": null
},
{
"label": "Disable Extra Spaces",
"description": "When set to true, it disallows spaces at the beginning and end of the element. Also it disallows entering 2 consecutive spaces between 2 words.",
"hideLabel": false,
"view": "boolean",
"config": {},
"key": "disableExtraSpaces",
"value": null
},
(...)
]
Shouldn't this value be "1", 1, or true?
I'd love to know if this is a bug I'm dealing with, and if someone can point me to where the issue may be happening in code I could try to submit a PR. I'm primarily a FED but happy to look.
If I understand correctly you are looking to set the 'default values' of configuration options for a custom property editor, via the 'defaultConfig' setting that exists on all property editors...
... which you might expect to work but ...
currently, I don't think it works that way...
The defaultConfig property is there to provide default configuration for a property editor, when the property editor is used in a context where there is no option to set the configuration via the UI of Umbraco...
When used as a straightforward property editor for a Document Type, the config for the property editor is set when creating the DataType... no need for defaultConfig but...
If using the property editor as a macro parameter however, there is no Data Type wrapper, and you might need to therefore set the default configuration for your property editor to enable it to work in this scenario (it's evolved over time, clearly using a Data Type as a Macro Parameter definition would make more sense!)
Anyway that is why the defaultConfig exists, to set those values when they cannot be set... currently this means when the configuration options are presented for configuring your custom property editor in the context of a DataType for a particular DocumentType the defaultConfig isn't checked, the user is expected to supply the config...
... but the configuration options for PreValues are also PropertyEditors... and they are being used here without the UI to set 'their' configuration, so in theory, I think you should be able to pass defaultValues to the property editors to set their individual default values when you configure them eg:
prevalues: {
fields: [
{
label: "Some Pre Value Setting",
description: "A setting to use in the property editor",
key: "somePreValueSetting",
view: "/path/to/view.html",
defaultConfig: {
"configOption": "someDefaultValue"
}
},
but this is somewhat speculative, as I can't find a good example, and the core property editors tend to supply configuration for prevalues in code...
So next question for a 'boolean' prevalue is there a configuration option for setting the default value?
if:
Then it looks like there is a configuration option to set the default value called 'default' and so something like:
prevalues: {
fields: [
{
label: "Disable Return",
description: "Enables/disables the use of the return-key.",
key: "disableReturn",
view: "boolean",
defaultConfig: {
"default": true
}
},
maybe what you are after for each of your boolean prevalues... (not sure if it's true, "1" or 1 to pass... (you'll need an app pool recycle in between each change to force Umbraco to read any change in config)
(finally if this is not how it works, eg I'm speculating wildy... then you could either rename your config options, so that the default value of false makes sense... eg Enable Return, Enable Double Return ...or you could create a new custom boolean property editor that was true by default, and use this as the source of the view in your prevalue configuration)
Anyway even if that perhaps isn't the definitive answer you are after, I hope it explains why the defaultConfig isn't currently doing what you expect it to do!
Thank you Marc for the thorough breakdown of why and how this is implemented. I think you made it very clear for it's original purpose, and it does indeed act the way you described.
... And no matter what I tried, I couldn't change the default state of the umbToggle through the package.manifest when it comes to creating a new data type based on this property editor.
I find this behavior odd and confusing (obviously). Do you? Would Umbraco HQ support a PR to "fix" this behavior?
Specifically > defaultConfig should be reflected in prevalue editors. If you are creating a new data type (-1 on the API request) we should return these defaultConfig values, not null.
I just thought I'd double check this, as naggingly in my head in V7, I think the way you had it first, is the way...
anyway, I had this in the package.manifest file
{
// you can define multiple editors
propertyEditors: [
{
/*this must be a unique alias*/
alias: "My.MarkdownEditor",
/*the name*/
name: "My markdown editor",
/*the icon*/
icon: "icon-code",
/*grouping for "Select editor" dialog*/
group: "Rich Content",
/*the HTML file we will load for the editor*/
editor: {
view: "~/App_Plugins/MarkDownEditor/markdowneditor.html"
}, prevalues: {
fields: [
{
label: "Disable Return",
description: "Enables/disables the use of the return-key.",
key: "disableReturn",
view: "boolean",
}
]},defaultConfig: { disableReturn: "1"}
}
]
,
// array of files we want to inject into the application on app_start
javascript: [
'~/App_Plugins/MarkDownEditor/markdowneditor.controller.js'
]
}
and lo and behold, the default configuration for the disableReturn checkbox is 'checked'...
... so your approach was right all along and my speculation was offbeat...
I've cut and paste your prevalues as you have above, and set true using "1"
Thanks so much for engaging with me. Also shout out to Sebastiaan for identifying another issue that was already fixed.
For the life of me, I couldn't get this to work. I was on Umbraco 8.0.2 and after upgrading to the latest 8.1.4 this works as expected. But I've learned some good stuff in the process (and dug through some Umbraco Core / CMS code too).
Now if you don't mind, I will do my walk of shame now.
Assigning default values (defaultConfig) for a custom property editor (prevalues) doesn't seem to have any effect?
I'd like to confirm if this is a bug or not. Perhaps I've done something wrong.
I'm building a property editor, and believe it or not this is the first time in which I've wanted to add a config (prevalues). Here's a sample of my package manifest:
Is my package.manifest correct?
You'll notice I tried a string, an int, and a boolean to try and set the value. None of these had an effect however.
So my property editor shows up, and I go to create a new data type. I select the new property editor I've created but none of the toggles are on. they are all off.
Looking at the request to
GetPreValues
in the back office, values for each editor are coming back asnull
. I have the following JSON result:Shouldn't this value be "1", 1, or true?
I'd love to know if this is a bug I'm dealing with, and if someone can point me to where the issue may be happening in code I could try to submit a PR. I'm primarily a FED but happy to look.
Hi Mark
If I understand correctly you are looking to set the 'default values' of configuration options for a custom property editor, via the 'defaultConfig' setting that exists on all property editors...
... which you might expect to work but ...
currently, I don't think it works that way...
The defaultConfig property is there to provide default configuration for a property editor, when the property editor is used in a context where there is no option to set the configuration via the UI of Umbraco...
When used as a straightforward property editor for a Document Type, the config for the property editor is set when creating the DataType... no need for defaultConfig but...
If using the property editor as a macro parameter however, there is no Data Type wrapper, and you might need to therefore set the default configuration for your property editor to enable it to work in this scenario (it's evolved over time, clearly using a Data Type as a Macro Parameter definition would make more sense!)
Anyway that is why the defaultConfig exists, to set those values when they cannot be set... currently this means when the configuration options are presented for configuring your custom property editor in the context of a DataType for a particular DocumentType the defaultConfig isn't checked, the user is expected to supply the config...
... but the configuration options for PreValues are also PropertyEditors... and they are being used here without the UI to set 'their' configuration, so in theory, I think you should be able to pass defaultValues to the property editors to set their individual default values when you configure them eg:
but this is somewhat speculative, as I can't find a good example, and the core property editors tend to supply configuration for prevalues in code...
So next question for a 'boolean' prevalue is there a configuration option for setting the default value? if:
maps to this core property editor:
https://github.com/umbraco/Umbraco-CMS/blob/7cc9747b2f58fdc98445636fe85d80f84cf7a569/src/Umbraco.Web/PropertyEditors/TrueFalseConfiguration.cs
Then it looks like there is a configuration option to set the default value called 'default' and so something like:
maybe what you are after for each of your boolean prevalues... (not sure if it's true, "1" or 1 to pass... (you'll need an app pool recycle in between each change to force Umbraco to read any change in config)
(finally if this is not how it works, eg I'm speculating wildy... then you could either rename your config options, so that the default value of false makes sense... eg Enable Return, Enable Double Return ...or you could create a new custom boolean property editor that was true by default, and use this as the source of the view in your prevalue configuration)
Anyway even if that perhaps isn't the definitive answer you are after, I hope it explains why the defaultConfig isn't currently doing what you expect it to do!
regards
Marc
Thank you Marc for the thorough breakdown of why and how this is implemented. I think you made it very clear for it's original purpose, and it does indeed act the way you described.
... And no matter what I tried, I couldn't change the default state of the
umbToggle
through thepackage.manifest
when it comes to creating a new data type based on this property editor.I find this behavior odd and confusing (obviously). Do you? Would Umbraco HQ support a PR to "fix" this behavior?
Specifically > defaultConfig should be reflected in prevalue editors. If you are creating a new data type (-1 on the API request) we should return these defaultConfig values, not null.
Thanks for your help mate!
Hi Mark
I just thought I'd double check this, as naggingly in my head in V7, I think the way you had it first, is the way...
anyway, I had this in the package.manifest file
and lo and behold, the default configuration for the disableReturn checkbox is 'checked'...
... so your approach was right all along and my speculation was offbeat...
I've cut and paste your prevalues as you have above, and set true using "1"
and it works as expected... (the config would have been cached if your site hadn't restarted in between each change...)
apologies.
Marc
Hi Marc,
Thanks so much for engaging with me. Also shout out to Sebastiaan for identifying another issue that was already fixed.
For the life of me, I couldn't get this to work. I was on Umbraco 8.0.2 and after upgrading to the latest 8.1.4 this works as expected. But I've learned some good stuff in the process (and dug through some Umbraco Core / CMS code too).
Now if you don't mind, I will do my walk of shame now.
is working on a reply...