Custom Property Editor view not loading (v12)
# help-with-umbraco
p
I am working on a custom property editor which extends the CheckboxList to enable a default value to be specified but I can't for some reason get it to load my view and fear I have been looking at it that long I am missing the obvious. I have the following defined on my class that inherits from
DataEditor
Copy code
[DataEditor(
    "RadioButtonListWithDefault",
    EditorType.PropertyValue,
    "RadioButtonList with default selection",
    "~/App_Plugins/MyProject/PropertyEditors/RadioButtonListWithDefault/RadioButtonListWithDefault.html",
    Group = Constants.PropertyEditors.Groups.Lists,
    ValueType = ValueTypes.Text)]
I am overriding
CreateConfigurationEditor
as follows: protected override IConfigurationEditor CreateConfigurationEditor() => new RadioButtonListWithDefaultConfigurationEditor(_ioHelper, _editorConfigurationParser); My ConfigurationEditor inherits
ConfigurationEditor<RadioButtonListWithDefaultConfiguration>
And my Configuration class looks like this:
Copy code
public class RadioButtonListWithDefaultConfiguration : ValueListConfiguration
{
    [ConfigurationField("default", "Default Value", "dropdown", Description = "Select the default value from the list")]
    public string Default { get; set; }
}
The view file exists in the specified location but is never loaded. I need it to be loaded so that I can set the default value in the UI. What am I missing?
r
I’m gonna ask some basic questions 1. Does it build ? 2. When you load the listing of data types , does the JavaScript error 3. Does the property show in the list ? 4. Any errors.. 5 converters??
p
Hey @Ravi I'm gonna answer your basic questions šŸ˜‰ 1. Yes 2. No (but quite likely as the HTML file is not loading there is no call to anything in the controller) 3. Yes, the property renders with the standard checkbox list editor but missing the dropdown for the default selector. If I change the view from
dropdown
to
textstring
it renders fine. But, that is to be expected since I think the reason the dropdown is not showing is that is has no data and it has no data because the view is not loaded. 4. No 5. No, not yet https://cdn.discordapp.com/attachments/1247540478442737744/1247859686947164280/image.png?ex=66618f65&is=66603de5&hm=69e735b45341f4b4953584c735a2393d056a4c262c02e9d493733ab12920127a&
This is why I suspect that I don't see anything. I'm wondering now if my approach is somehow wrong. How do I push the prevalues into the dropdownlist that I have told the ConfigurationField to use for that config. Do I need to create my own view? https://cdn.discordapp.com/attachments/1247540478442737744/1247861047377788948/image.png?ex=666190a9&is=66603f29&hm=5c23cee799d9789812c6e3f8442707601bc8a973202656105da7c6ec4b3244e2&
OK, I've kinda answered my own question here. If I change my configuration class to use my own view - it does so (no surprise there!)
Copy code
public class RadioButtonListWithDefaultConfiguration : ValueListConfiguration
{
    [ConfigurationField("default", "Default Value", "~/App_Plugins/MyProject/PropertyEditors/RadioButtonListWithDefault/RadioButtonListWithDefault.html", Description = "Select the default value from the list")]
    public string Default { get; set; }
}
However, it seems a little pointless when there is already one that will do the job just fine but then question is - how do I push the items into the dropdown view using this approach?
This is what happens when you look at things for too long 😳 What I actually need here is a custom prevalue editor for the default value in the datatype config. My property editor is fine. Just swatting up on how I can add one.
r
okay .. that s why i like to ask the simple questions.. 8- 9 times out of ten you know or can see the answer, your brain is not firing , so by forcing you to walk back through and validate yourself..
p
Thanks @Ravi I'd still like to know, if/how I might be able to use the existing Umbraco view for dropdown and push the items from
config.Items
collection into it. So far I've been unsuccessful. Wherever possible I'd prefer not to be reinventing the wheel.
r
So you woyld have to figure out a way to identify if its the default or your specialised one , and then when its building it add you custom code to populate it Its been a long time since i have done this .. however you may want to look at Contentment which is a package which allows a lot of this kind of thing.. https://our.umbraco.com/packages/backoffice-extensions/contentment/ its alos open source so you can have a look atnd see whats been done
Something rattling in the back of my brain says .. I've always done them as separate .. but off the top of my head I can't remember the reason etc
p
Thanks @Ravi Doing them separate I am sure is easier but will take a look at Contentment.
For anyone that might be interested I finally have a working version of this and it seems far more complicated than it really should be: https://gist.github.com/ProNotion/bc1692a02085f4e1d3d3a22214fbbbe4
2 Views