Copied to clipboard

Flag this post as spam?

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


  • Lesley 107 posts 349 karma points
    Mar 30, 2016 @ 00:03
    Lesley
    1

    Mandatory datepicker allows non-date text

    We have an Umbraco Form with a mandatory DatePicker field.

    Have discovered that users can enter random text into this field eg "hgjfjk" and it passes validation, although the data is not saved and so does not appear in any of the workflow emails.

    How do we ensure that only valid dates are accepted?

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Mar 30, 2016 @ 06:18
    Dennis Adolfi
    0

    Hi Lesley!

    Tested the same thing just now and you are right, the forms gets sent but the input from det datefield is lost. Since there is now option for Regex on the Datepicker field one cant solve it that way either.

    Maybe you should report this to the issue tracker: http://issues.umbraco.org/issues

    (I used Umbraco version 7.4.2 with the latest version of Forms)

  • Lesley 107 posts 349 karma points
    Mar 30, 2016 @ 19:22
    Lesley
    1

    Thanks Dennis,

    Have reported this to the issue tracker:

    http://issues.umbraco.org/issue/CON-953

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Mar 31, 2016 @ 06:24
    Dennis Adolfi
    0

    Hi again Lesley!

    Great, than you´ll probobly be contacted soon about this. Hope that it workes out for you.

    You could fix it in the meantime with just simple Regex validation, but since its only clientside and no severside validation, its not bullet proof.

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    May 24, 2018 @ 09:26
    Ismail Mayat
    0

    So I recently had this and I solved it quite easily:

    In the partial FieldType.DatePicker on the input add the following attributes: data-msg-date="The field DateTime must be a date." data-rule-date="true"

    Jquery validation will do its magic.

    Im guessing server side you will still have issue but at least its better than having no validation at all.

    Regards

    Ismail

  • Satpal Gahir 18 posts 88 karma points
    Feb 11, 2020 @ 13:25
    Satpal Gahir
    0

    the above works, but the validation seems to accept only MM-DD-YYYY value. if you put in a normal date (DD/MM/YYYY) it doesnt let you pass.

    Will check if there is something under the hood that i can change. (config)

  • Satpal Gahir 18 posts 88 karma points
    Feb 11, 2020 @ 14:24
    Satpal Gahir
    0

    you may need this for non american dates, in addition to the above.

    $(function () {
        $.validator.methods.date = function (value, element) {
            return this.optional(element) || moment(value, "DD-MM-YYYY", true).isValid();
            return this.optional(element) || moment(value, "DD/MM/YYYY", true).isValid();
        }
    });
    

    i've added it to the DatePicker view. i suppose you can put it anywhere.

Please Sign in or register to post replies

Write your reply to:

Draft