How can I create a custom Form Component for a existing Data Type?
We have a situation where we'd like to use a different Form Component (in this case a simple input field) for an existing Data type (the "Date and time" one). Is this possible?
This is what the Form Component looks like:
public class DateTimeInputComponent : FormComponent<DateTimeInputComponentProperties, DateTime>
This is what the properties look like:
public class DateTimeInputComponentProperties : FormComponentProperties<DateTime> { public DateTimeInputComponentProperties() : base(FieldDataType.DateTime) { }
but it's still not showing up as an option.
Is there any way to do this?
In the picture below, the "Datetime input" is the default one provided by Kentico. But we'd like to add a custom Form Component to that list of options.
Answers
Did you register it?
[assembly: RegisterFormComponent(DateTimeInputComponent.IDENTIFIER, typeof(DateTimeInputComponent), "Custom DateTime input")]
Yup!
[assembly: RegisterFormComponent(
DateTimeInputComponent.IDENTIFIER,
typeof(DateTimeInputComponent),
"HTML 'datetime-local' Input",
IsAvailableInFormBuilderEditor = true,
IconClass = "icon-edit",
ViewName = "/Features/Form/DateTimeInputComponent/Default.cshtml")
]
Make sure you are using the right C# types because Xperience currently has 2 sets of Form Components that are not interoperable.
Form Components from the Form Builder (or Legacy Page Builder)
- namespace -
Kentico.Forms.Web.Mvc
- namespace -
UI Form Components based on React and Xperience administration UI technology
- namespace -
Kentico.Xperience.Admin.Base.Forms
- namespace -
These are in different namespaces and it's unfortunately very easy to confuse them.
If you want to see a functioning example of custom UI Form Components (and custom data types) check out the Kentico Community Portal source code or read the blog post Embedded structured content and the power of custom data types.
You can also see an example of a UI Form Component registered for an existing data type (text/string
).
To answer this question, you have to login first.