Jump to:

10844 Posts in 2515 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » Userforms date validation not working

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 2257 Views
  • ColinMcCrory
    Avatar
    Community Member
    2 Posts

    Userforms date validation not working Link to this post

    Hi!

    I've been having a slight problem validating date picker fields with userforms.

    If I create a date field and default it to today’s day it will be displayed in the format "6 Sep 2010" When this is submitted it validates.

    If I then use the date picker to choose a different date it will be displayed in the format "09/07/2010" the page will be submitted and pass the javascript validation but you'll be redirected back to the form with an error message displayed: "Please enter a valid date format (d MMM yyyy)"

    I've had a look through the source code and can’t find where this validation is done or where the default date output is created, Could anyone point me in the right direction.

    On another note, I also can’t find the code that creates the javascript output; I’d like to change some of the validation rules there too.

    I've put a test form up so any of you can take a look at http://formbuilder.kolin.me.uk/test/test-form/

    I've also posted my template's Page.ss which isn’t particularly complicated file at http://pastie.org/1141548

    Thanks in advance
    Colin

  • ColinMcCrory
    Avatar
    Community Member
    2 Posts

    Re: Userforms date validation not working Link to this post

    I've found the solution to the first problem.

    Changing line 51 of userforms/code/editor/EditableDateField.php from

    $('input[name^=EditableDateField]').attr('autocomplete', 'off').datepicker();   

    to

    $('input[name^=EditableDateField]').attr('autocomplete', 'off').datepicker({dateFormat: 'd M yy'});   

    Makes the date picker output the date in the same format as the current date.

    Now just to find out where the rest of the javascript comes from.

  • CHD
    Avatar
    Community Member
    217 Posts

    Re: Userforms date validation not working Link to this post

    isn't this just managed by the locale you set in config?
    it worked for me anyway... i added this:
    // Set the site locale
    i18n::set_locale('en_GB');

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: Userforms date validation not working Link to this post

    I have a simulair problem, when you click on the datePicker, you get the date, but the validation says it's not correct/filled in.

    I've downloaded the latest version from gitHub today.. but the validation is going wrong.

    It displays the date as 31 Oct 2011 for instance.

    i've set the site to dutch in the config
    i18n::set_locale('nl_NL');
    setlocale(LC_ALL, 'nl_NL');

    Any idea how to fix this?

  • CHD
    Avatar
    Community Member
    217 Posts

    Re: Userforms date validation not working Link to this post

    first thing to check, the time/date settings for your user account under the security tab!

  • RuthAdele
    Avatar
    Community Member
    18 Posts

    Re: Userforms date validation not working Link to this post

    I'm having the same issue borriej.
    I've check my date/time setting - all on Default. No difference, I still get a validation error that the field is empty when it clearly is not..

    Anyone else have any ideas?

    **UPDATE
    It seems that it only breaks if you create a DateField, make it required. Save it. And then change it back to being not required.
    I deleted the instance of DateField that was being problematic, and added it again, and all seems to be working as expected.

    Should a bug like this be reported?

  • DomS
    Avatar
    Community Member
    1 Post

    Re: Userforms date validation not working Link to this post

    We are experiencing the same issue with our sites. When we add 'required' to a date field suddenly the locale set to en_US when the system is setup for en_GB.

    Weird!

    If we find a solution we'll post.

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: Userforms date validation not working Link to this post

    Report it and see what Will has to say since it seems others have it too?

    2257 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.