Datetime vs date type in Editor

Datetime vs date type in Editor

DatagaardDatagaard Posts: 68Questions: 20Answers: 3

I have some strange behaviour occurring in the Editor with a field of type datetime.

This is the first field in the editor, and gets focus by default. But when attempting to set the focus to the second control in the editor via the on open event, if the first control is of type datetime, it still obtains focus, but if I change the control to a type of date, then the second control gets focus. BUT, the date control no longer displays the correct data.

Editor Code:

$(document).ready(function() {
    var editor = new $.fn.dataTable.Editor( {
        ajax: 'php/table.CMBSCodes.php',
        table: '#CMBSCodes',
        fields: [
            {
                "label": "Effective Date:",
                "name": "CMBSCodes.EffectiveDate",
                "type": "datetime",
                "format": "ddd, D MMM YY"
            },
            {
                "label": "Schedule Type:",
                "name": "CMBSCodes.ScheduleTypeID",
                "type": "select"
            },

...

editor.on( 'open', function (e, mode, action){
    if (action == 'edit'){
            editor.field( 'CMBSCodes.ScheduleTypeID' ).focus();
    }
   });

PHP Code:

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'CMBSCodes', 'ID' )
    ->fields(
        Field::inst( 'CMBSCodes.EffectiveDate' )
            ->validator( 'Validate::notEmpty' )
            ->validator( 'Validate::dateFormat', array( 'format'=>'D, j M y' ) )
            ->getFormatter( 'Format::date_sql_to_format', 'D, j M y' )
            ->setFormatter( 'Format::date_format_to_sql', 'D, j M y' ),
        Field::inst( 'CMBSCodes.ScheduleTypeID' )
            ->options( 'CMBSScheduleType','ScheduleTypeID', 'TypeDescription')
            ->validator( 'Validate::dbValues' ),

Here is the screen shot for datetime control in Editor:

And with the date control in Editor.

What have I missed to cause this?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Could you try using the focus option of the form-options object in order to set the initial focus for the table please? That should be a more reliable way of doing it, otherwise focus will be triggered on multiple fields, which is probably what is causing the issue you are seeing.

    Allan

  • DatagaardDatagaard Posts: 68Questions: 20Answers: 3

    Thanks Allan,

    Used

    formOptions: {
                main: {
                    focus: 1,           
                }       
            }
    

    Works

This discussion has been closed.