Quantcast
Channel: Editor — DataTables forums
Viewing all articles
Browse latest Browse all 3740

Unique date field with formatter

$
0
0

Hi, I would like to make my date-field unique, but I'm using set- and get-formatter (server-side) with the editor.

Client-Side:

// ... 
editor = new $.fn.dataTable.Editor( { 
    ajax: "scripts/editor.php", 
    table: "#holidays_overview", 
    fields: [{ 
            label: "Datum", 
            name: "appointments.day", 
            type: "date",
            opts: {
                language: "de",
                format: "dd.mm.yyyy",
                showOn: "focus",
                todayHighlight: "true"
            }
        },{
            label: "Feiertag",
            name: "appointments.event"
        }
    ],
    i18n: DTE_i18n
// ...
});

Server-Side:

// ...
Field::inst( 'appointments.day' )
->validator( Validate::notEmpty( ValidateOptions::inst()
    ->message( 'Bitte geben Sie ein Datum ein.' ) )
)
->getFormatter( Format::dateSqlToFormat( 'd.m.Y' ) )
->setFormatter( function( $val, $data, $opts ) {
    return date( 'Y-m-d', strtotime( $val ));
} )
->validator( Validate::unique( ValidateOptions::inst()
    ->message( 'Das Datum ist bereits vergeben.' ) )
)
// ...

But currently I can still create more entries with the same date.
I guess it's because the unique-method compares the database value in format "YYYY-MM-DD" and client-side value in format "DD.MM.YYYY".

Is it possible to set the formatted values to unique? Like include an formatter into the unique method?
Thank you in advance.


Viewing all articles
Browse latest Browse all 3740

Trending Articles