Editor - date field - can not format date and have bubble editing at the same time

Editor - date field - can not format date and have bubble editing at the same time

asleasle Posts: 96Questions: 28Answers: 0

I have a date field in my table. I add a pencil to trigger bubble editing. This works great. But I am trying to format the shown date. When I edit the date, the datepicker shows my correct date format (DD-MM-YYYY) but the shown date is in the format from mySQL -> YYYY-MM-DD. My edit field looks like this;

<td class="  pencil">2022-09-10 <i class="fa fa-pencil"></i></td>

My function for bubble editing of several fields.

   $('#my_table').on( 'click', 'tbody td i', function (e) {
        e.stopImmediatePropagation(); // stop the row selection when clicking on an icon
        editor.bubble( $(this).parent() );
        } );  

In EDITOR the field works fine, displays my date format and saves in SQL format:

            },{
                label: "Monteringsdato",
                name: "montdato",
                type: "datetime",
                def: function () { return new Date(); },
                displayFormat: 'DD-MM-YYYY',
                wireFormat: 'YYYY-MM-DD',
                keyInput: false
            },{

In DATATABLE the same field:

           { data: "montdato" ,
               render: function ( data, type, row ) {
                if (data == null) {return ' <i class="fa fa-pencil"></i>'} else {
                    return  data + ' <i class="fa fa-pencil"></i>';
                }
                return data;
            }},

I used this formatter which works fine on other date fields but has **no effect **on my field which is also a "bubble edit" field.

     columnDefs: [
            {targets: [11,20,21], // 11 is the field "montdato"
                render: function(data){
                return moment(data).format('DD-MM-YYYY');
            }}, 

I also tried this code which works also fine on all fields but not on my "bubble edit" field

          { targets: [11,20,21],
            render: DataTable.render.datetime('DD-MM-YYYY' )  
            }, 

Is there any reason why the date formating has no effect on a cell that has a "bubble edit" function? As soon as I remove the function for the bubble edit, the format works fine. So something is saying it already has a function so ignore?

Answers

  • asleasle Posts: 96Questions: 28Answers: 0

    So I found out that if I edited the controller php file, I get the correct format. But I still wonder why it worked before and why the date format functions had no effect on the bubble-edit-field? Here is the field defined in the controller. The ->getFormatter gives my wanted format.

         Field::inst( 'montdato' )
            ->validator( Validate::dateFormat( 'Y-m-d' ) )
                ->getFormatter( Format::dateSqlToFormat( 'd-m-Y' ) )
                ->setFormatter( Format::dateFormatToSql('Y-m-d' ) ),
    
  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Not immediately sure I'm afraid. We have tightened things up so what used to be allowed, even although it wasn't strictly right, would now be rejected. I suspect that is what was happening here.

    Allan

Sign In or Register to comment.