Editor date field

Editor date field

rwgreenwoodrwgreenwood Posts: 43Questions: 13Answers: 0

Hi,
I have a date field in an editor form and do not want to use a datepicker because this is historical information and many of the dates are older. So I do not have the field set as a type of date. I want to be able to validate with a single digit month and day. I have this:

Field::inst( 'start_date' )
            ->validator( 'Validate::dateFormat', array(
                'format' => 'm/d/Y',
                "message" => "Please enter a date in the format m/d/y")
            ) 
            ->getFormatter( 'Format::date_sql_to_format', 'm/d/Y' )
            ->setFormatter( 'Format::date_format_to_sql', 'm/d/Y' )            
        ,

And have tried many different combinations for the format in the validator. But it will only validate if all digits are entered i.e.'01/01/2001'

Any ideas? Thanks in advance.

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394
    Answer ✓

    I suspect you will need to provide your own formatters. I needed partial dates (00-00-1923, or 01-05-0000, for example) and wrote my own formatters as the Editor's PHP library relies on PHP date functions which insist on "correct" date formats.

  • rwgreenwoodrwgreenwood Posts: 43Questions: 13Answers: 0

    Thanks for the reply. It helped lead me to the PHP API documentation where I can now see what I need to do.

This discussion has been closed.