Copied to clipboard

Flag this post as spam?

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


  • Kevin Jump 2312 posts 14698 karma points MVP 7x c-trib
    Oct 16, 2015 @ 09:27
    Kevin Jump
    0

    Umbraco Forms - Merging multiple inputs on fieldtype.

    Hello,

    Using Umbraco Forms 4.1.4 what is the best practice for developing an field type that has multiple inputs ?

    I have a custom field type, with three inputs (in this example its day, month year) and i want to merge them into a single (date) field.

    in the FieldType class I have Overrriden ProcessSubmittedValue to merge the three fields into one and return that in the vals object.

    public override IEnumerable<object> ProcessSubmittedValue(Field field, IEnumerable<object> postedValues, HttpContextBase context)
    {
        LogHelper.Info<SimpleDatePicker>("ProcessSubmittedValue");
    
        var vals = new List<object>();
    
        var day = int.Parse(context.Request["dob-day"].ToString());
        var month = int.Parse(context.Request["dob-month"].ToString());
        var year = int.Parse(context.Request["dob-year"].ToString());
    
        var date = new DateTime(year, month, day);
    
        vals.Add(date);
    
        return vals; 
    }
    

    on submit this gets called and the value does get submitted - i can see that in the form entries.

    however when i set it to mandatory, the validation fails - the JQuery validation passes - it appears to fail on the server side.

    I have overriden ValidateFeilds . with the below.

    public override IEnumerable<string> ValidateField(Form form, Field field, IEnumerable<object> postedValues, HttpContextBase context)
    {
        LogHelper.Info<SimpleDatePicker>("Validate Field? {0}", () => field.Alias);
    
        if ( field.Values != null && field.Values.Any() )
        {
            LogHelper.Info<SimpleDatePicker>("Validate Has Values");
            var date = (DateTime)field.Values.First();
            return new List<string>();
        }
    
        LogHelper.Info<SimpleDatePicker>("Passing to base");
        return base.ValidateField(form, field, postedValues, context);
    }
    

    but looking in the logs, i never get to "Has Values" -

    Do i access the values via context like i have done in the ProcessSubmit ? or am i missing something to get the values in the Field.Values for validation ?

Please Sign in or register to post replies

Write your reply to:

Draft