dateformat

dateformat

paintitblackpaintitblack Posts: 60Questions: 20Answers: 0

Hi,

in my example I tried to set a dateformat in this way:
{
label: "SellDate:",
name: "sellDate",
def: function () { var d = new Date(); return new Date(d.getFullYear(), 11, 31); },
type: "datetime",
dateFormat: "dd.mm.YYYY"
},

or
{
label: "Date:",
name: "_stocks_fees.date",
type: "datetime",
dateFormat: "dd.mm.YYYY"
}
but it seems that the dateFormat variables were ignored and the date in the form and in the tables is still YYYY-MM-DD.

What did I wrong?

Thanks for any support

Patrick

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    Its hard to say without a link to a test case. The code above looks okay. Have you included the Moment.JS library (which is returned for the datetime field if you are using a custom format.

    Allan

  • paintitblackpaintitblack Posts: 60Questions: 20Answers: 0

    I included the http://momentjs.com/downloads/moment.js, but at my example http://wechselstube.host4free.de/start5.php it still don't work.

    I tried it in the forms (e.g. on Edit) and also on the child table.

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    Ah. Two things:

    1. It should be called format for the datetime field type.
    2. The format option for Editor doesn't effect the format that is displayed in the DataTable. Only the value that is read by and shown in the datetime input element.

    If you want to use a different format in the DataTable, you'd need to return the format needed from the server-side. Editor's PHP libraries have formatters for that sort of thing.

    Allan

  • paintitblackpaintitblack Posts: 60Questions: 20Answers: 0

    This works not bad:
    Field::inst( '_stocks_fees.date' )
    ->validator( 'Validate::dateFormat', array(
    'empty' => false,
    'format' => 'd.m.Y'
    ) )
    ->getFormatter( 'Format::datetime', array(
    'from' => 'Y-m-d H:i:s',
    'to' => 'd.m.Y'
    ) )
    ->setFormatter( 'Format::datetime', array(
    'from' => 'd.m.Y',
    'to' => 'Y-m-d H:i:s'
    ) )

    but the datePicker ignore the format and still uses this format YYYY-MM-DD.

    Have you a least advice for me how to fix this issue?

    Thank you very very much

    Patrick

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    Did you update the client-side Javascript to use format rather than dateFormat?

    Allan

  • paintitblackpaintitblack Posts: 60Questions: 20Answers: 0

    Yes that's was it:

    Now it works as expected:

    type: "datetime",
    format: "DD.MM.Y"

    Thank you very much

This discussion has been closed.