Date is not in the expected format

Date is not in the expected format

whitbaconwhitbacon Posts: 40Questions: 2Answers: 0

I have a simple page and have the following

php

Editor::inst( $db, 'mentorship_info', 'mentorship_id' )
    ->fields(
        Field::inst( 'first_meeting_date' )
            ->validator( 'Validate::dateFormat', array( 'format'=>'m-d-y' ) )
            ->getFormatter( 'Format::date_sql_to_format', 'm-d-y' )
            ->setFormatter( 'Format::date_format_to_sql', 'y-d-m' )
    )
    ->process( $_POST )
    ->json();

jscript

    fields: [
            {
                "label": "date",
                "name": "first_meeting_date",
                "type": "date",
                "dateFormat": "mm-dd-y"
            }

On submit it gives

Date is not in the expected format

The json looks correct eg '2015-08-25'

I cannot figure out where this error comes from. I loaded a date field from generator same error.

http://inspiredata.org/datetest/mentorship_info.html

looking at developer tools this is what is sent

action:create
data[0][first_meeting_date]:2015-08-21

the repsons is this

{"fieldErrors":[{"name":"first_meeting_date","status":"Date is not in the expected format"}],"data":[]}

Answers

  • whitbaconwhitbacon Posts: 40Questions: 2Answers: 0

    sorry fixed php to this

    ->validator( 'Validate::dateFormat', array( 'format'=>'m-d-y' ) )
                ->getFormatter( 'Format::date_sql_to_format', 'm-d-y' )
                ->setFormatter( 'Format::date_format_to_sql', 'm-d-y' )
        )
    
  • whitbaconwhitbacon Posts: 40Questions: 2Answers: 0

    still not working

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Hi,

    The date format being submitted is Y-m-d from your above code, but the validator is checking for m-d-y which is why it is rejecting it.

    For dates which are anything other than ISO8601 I would suggest you probably need to include a date picker library such as jQuery UI (which Editor has built in support for). There are other options available as well, but that one is well supported.

    Allan

  • whitbaconwhitbacon Posts: 40Questions: 2Answers: 0

    I fixed the php as in my second post where everything is m-d-y. This was working, and then I downloaded a new version of something from datatables generator. Updated all files and it stopped working?

  • whitbaconwhitbacon Posts: 40Questions: 2Answers: 0

    The Editor Generaotr is creating code that does not work.

    I changed the php to this and all works

    ->validator( 'Validate::dateFormat', array( 'format'=>'Y-m-d' ) )
            ->getFormatter( 'Format::date_sql_to_format', 'Y-m-d' )
            ->setFormatter( 'Format::date_format_to_sql', 'Y-m-d' ),
    

    Even though the scree is using 08/01/2015.

    It's as if the validation is happening after the formating?

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    I have a suspicion that you are using Chrome. It has a built in date picker which is super handy, but it doesn't really support formatted dates. If you were to try in Firefox, does it work?

    To have it work in all browsers (which Generator should do - I'll fix that!) we need to include something like jQuery UIs date picker or some other date picker library. Editor has built in support for jQuery UI date picker, so you could include that and set an appropriate format for it.

    Regards,
    Allan

This discussion has been closed.