So long as you implement the FieldType type, Forms/Contour will load your custom type at runtime and make it available to you inside the CMS.
The Setting would be something like this:
[Setting("Regex",
description = "Enter a regex",
view = "textfield")]
public string Regex { get; set; }
You would then apply the Regex to the field value in the ValidateField method like you would any regex and return a list of strings to specify an error being found - these are the messages that will be displayed to the user.
Sorry I've just noticed that FieldType has a Boolean property called 'SupportsRegex', you could try simply setting this in the constructor rather than playing around with custom settings.
public ExtendedDatePicker()
{
Id = new Guid("46351f37-dc90-4067-9a98-e2ea24871a30"); // Set your own GUID here
Name = "Extended Date Picker";
Description = "Allows date picking with regex validation";
Icon = "icon-autofill";
DataType = FieldDataType.DateTime;
SupportsRegex = true;
}
That might work, but I haven't tested this in any way, so I don't know if the Regex checking is handled by the base type or if you need to implement this in the ValidateField method.
Datepicker field regex not possible?
Is it possible from the forms interface to give a regex to a datepicker field, because there isn't a check now if the datepicker field is correctly
Hi Rick,
You would need to create your own Field Type and add the Regex input box as a Setting, documentation for this is available here:
Developer Docs
So long as you implement the FieldType type, Forms/Contour will load your custom type at runtime and make it available to you inside the CMS.
The Setting would be something like this:
You would then apply the Regex to the field value in the ValidateField method like you would any regex and return a list of strings to specify an error being found - these are the messages that will be displayed to the user.
Let me know how you get on.
/Chris
Sorry I've just noticed that FieldType has a Boolean property called 'SupportsRegex', you could try simply setting this in the constructor rather than playing around with custom settings.
That might work, but I haven't tested this in any way, so I don't know if the Regex checking is handled by the base type or if you need to implement this in the ValidateField method.
Have a play, let me know!
/Chris
is working on a reply...