I've created a custom property editor and using it as a macro parameter. The property renders fine and shows everything as it should.
The issue that I have is with the saving and deserialization of the property data. The data gets saved as the JSON parsed into a html string.
My JSON object {test: "pass"}
gets converted into {"test":"pass"}
.
Up until the submit, everything is as it should be, but when the submit button is pressed, the html string is what gets passed to the /umbraco/backoffice/UmbracoApi/Macro/GetMacroResultAsHtmlForEditor
endpoint.
Here is what my package.manifest
looks like:
{
propertyEditors:
[
{
alias: "propertyAlias",
name: "Property Name",
icon: "icon-code",
isParameterEditor: true,
editor:
{
valueType: "JSON",
view: "path/to/editor"
}
}
],
javascript:
[
"path/to/controller"
]
}
I've tried playing around with the valueType
property, but that doesn't do anything... the request always gets sent as shown above.
Going by Tim's answer, it seems there isn't much that can be done in the property editor config.
I've decided to decode the parameter value in the macro and then deserialize it into a custom model. For anyone else who comes across this issue:
var parameterValue = Model.GetParameterValue<string>("paramAlias");
var parameterValueDecoded = WebUtility.HtmlDecode(parameterValue);
var modelObject = JsonConvert.DeserializeObject<MyCustomModel>(parameterValueDecoded);
Not the most optimal solution, but it works.