How to create custom server-side validation for property editors?
I'm trying to add a custom server-side validation to a property editor and by looking at the core code I saw that there are some interfaces and attributes that can be used (IPropertyValidator and ValueValidatorAttribute) to specify that a property has to be validated on the server side, but I cannot find any documentation on how to use it and even cannot find anything on the forum.
Am I missing something obvious?
Has anyone some links or samples on how to make them?
Good question. Looks like the code related to that isn't heavily commented. As best I can tell, seems like it's only used with regard to package.manifest files. Maybe it's an optional attribute that's only to be used in different scenarios? Might be worth trying to implement IPropertyValidator and make use of it in your property editor without the ValueValidatorAttribute.
I created a Property Editor for an existing plug-in stored in the App_Plugins, the purpose is to create a validator for that plugin which is a date range picker. But this seems not to work, as my Property Editor is registered twice and it breaks the frontend completely.
Is there a way to tell my PropertyEditor to use a specific manifest file and not to be registered twice ? That manifest file contains the views, the javascripts, css dependencies, and the available prevalues.
How to create custom server-side validation for property editors?
I'm trying to add a custom server-side validation to a property editor and by looking at the core code I saw that there are some interfaces and attributes that can be used (
IPropertyValidator
andValueValidatorAttribute
) to specify that a property has to be validated on the server side, but I cannot find any documentation on how to use it and even cannot find anything on the forum.Am I missing something obvious?
Has anyone some links or samples on how to make them?
Thx
Not sure if there is something more obvious, but searching through the Umbraco core source code I came across this: https://github.com/umbraco/Umbraco-CMS/blob/5397f2c53acbdeb0805e1fe39fda938f571d295a/src/Umbraco.Web/PropertyEditors/RichTextPreValueEditor.cs
The bottom of that file has some guidance on using a validator with a property editor (in this case, a regex validator). Here's the regex validator implementation (implements
IPropertyValidator
): https://github.com/umbraco/Umbraco-CMS/blob/5397f2c53acbdeb0805e1fe39fda938f571d295a/src/Umbraco.Core/PropertyEditors/RegexValidator.csI also found the validators referenced in the core boot manager, so not sure what that's about (maybe that's not necessary for new validators): https://github.com/umbraco/Umbraco-CMS/blob/3f9cfbb4221a1e6601852a79d21d61c4a3c798f4/src/Umbraco.Core/CoreBootManager.cs#L443
Another simple example is the decimal validator:
Thank you. This is indeed where I looked at.
I'm wondering what the
ValueValidator
attribute is used for.Good question. Looks like the code related to that isn't heavily commented. As best I can tell, seems like it's only used with regard to
package.manifest
files. Maybe it's an optional attribute that's only to be used in different scenarios? Might be worth trying to implementIPropertyValidator
and make use of it in your property editor without theValueValidatorAttribute
.Seems like the manifest stuff is explained a bit here: https://our.umbraco.org/forum/umbraco-7/developing-umbraco-7-packages/54788-V7-packagemanifest-validation-array
Some documentation would be nice though.
Indeed, from some comments on that post it looks like they are only used in core validators. Thx!
So basically ones creates a
IPropertyValidator
and adds it to the collection ofValidators
in the constructor of ones own Property Editor.Looks easy enough :)
Hi guys,
I created a Property Editor for an existing plug-in stored in the App_Plugins, the purpose is to create a validator for that plugin which is a date range picker. But this seems not to work, as my Property Editor is registered twice and it breaks the frontend completely.
Is there a way to tell my PropertyEditor to use a specific manifest file and not to be registered twice ? That manifest file contains the views, the javascripts, css dependencies, and the available prevalues.
Thanks,
Laurent
is working on a reply...