Copied to clipboard

Flag this post as spam?

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


  • kleptbit 42 posts 98 karma points
    Jun 30, 2017 @ 13:56
    kleptbit
    0

    Format DateTime with moment/Pikaday for submission to external SQL database

    I have a form from a datasource in Umbraco 6.0.1 made from an existing table in an external SQL DB. It needs an int field type, which I have made, and a DateTime field type. I've altered the existing Date field type, because I couldn't get a new one to work.

    So, I have altered Pikaday.js with Owen Mead's fork to include DateTime, and altered Themes > DatePicker.cshtml according to Matthew's post on the subject. I have formatted the dates in various ways, but keep getting the following String was not recognised as a valid DateTime error:

    [FormatException: String was not recognized as a valid DateTime.] System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) +12705754 System.Convert.ToDateTime(String value, IFormatProvider provider) +72 System.String.System.IConvertible.ToDateTime(IFormatProvider provider) +15 System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +12698556 System.Convert.ChangeType(Object value, Type conversionType) +32 Umbraco.Forms.Core.Providers.DatasourceTypes.MsSql.InsertRecord(Record record) +1689 Umbraco.Forms.Web.Services.RecordService.storeRecord(Record record, Form form) +1556 Umbraco.Forms.Web.Services.RecordService.Approve(Record record, Form form) +497 Umbraco.Forms.Web.Services.RecordService.Submit(Record record, Form form) +786 Umbraco.Forms.Web.Controllers.UmbracoFormsController.SubmitForm(Form form, FormViewModel model, Dictionary2 state, ControllerContext context) +2258 Umbraco.Forms.Web.Controllers.UmbracoFormsController.GoForward(Form form, FormViewModel model, Dictionary2 state) +216 Umbraco.Forms.Web.Controllers.UmbracoFormsController.HandleForm(FormViewModel model, Boolean captchaIsValid) +811

    Does anyone know how I should be formatting these in the DatePicker.cshtml please? I currently have this code:

            $(".datepickerfield")
            .each(function () {
                var currentId = this.id;
                new Pikaday({
                    field: document.getElementById(currentId),
                    yearRange: "@datePickerYearRange",
                    i18n: local,
                    format: "DD-MM-YYYY LTS",
                    onSelect: function (date) {
                        setShadow(currentId.replace("_1", ""), date);
                    },
                    showTime: true,
                    showMinutes: true,
                    use24hour: false,
                    autoClose: false
                });
            });
    
        function setShadow(id, date) {
            var value = moment(date).format('DD-MM-YYYY LTS');
            var field = document.getElementById(id);
            field.value = value;
        }
    });
    
  • Aaron 22 posts 93 karma points
    Oct 09, 2018 @ 16:25
    Aaron
    0

    We have the same problem, does anyone have a solution?

  • Aaron 22 posts 93 karma points
    Oct 10, 2018 @ 11:02
    Aaron
    0

    Actually our problem was slightly different to OP.

    We had two adjacent modified date-time picker fields which were similarly named.

    Breaking in the Umbraco Forms code with dotPeek seemed to show the second field value was somehow null at the point of validation leading to the form being rejected.

    Renaming the fields appears to have fixed the problem.

Please Sign in or register to post replies

Write your reply to:

Draft