Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rick van der Meij 35 posts 135 karma points
    Jun 16, 2015 @ 13:16
    Rick van der Meij
    0

    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

  • Chris Wilson 100 posts 377 karma points
    Jun 18, 2015 @ 09:02
    Chris Wilson
    0

    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:

    [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.

    Let me know how you get on.

    /Chris

  • Chris Wilson 100 posts 377 karma points
    Jun 18, 2015 @ 09:14
    Chris Wilson
    0

    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.

    Have a play, let me know!

    /Chris

Please Sign in or register to post replies

Write your reply to:

Draft