Datatables Editor - Bug with upload?

Datatables Editor - Bug with upload?

robgeorgeukrobgeorgeuk Posts: 3Questions: 2Answers: 0

I see this issue at https://editor.datatables.net/examples/advanced/upload.html and on my local system.

If I edit any record (without uploading an image) and click update, the edit form stays open instead of closing. If I refresh the page then I'm unable to edit this record again. I click the edit button but nothing happens.

This seems to be related to the image field getting set to 0 as opposed to NULL. If I edit a record and add an image then everything works as expected.

Is this a bug or is there someway to avoid 0 being written when no image is uploaded?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Hi,

    Thanks for letting me know about this. Interestingly the behaviour seems to differ between MySQL versions - 5.6 (at least for me locally) is rejecting the edit with an error while 5.5 is writing in 0. Both are not what we want of course...

    The issue is that when there is no image, the client-side is submitting an empty string as the HTTP variable. There is no way to distinguish between an empty string and null (string the HTTP variables are unformatted) so there is a nullEmpty formatter available to be used which will write null to the database when an empty string is submitted.

    Long story short, we need to use the nullEmpty formatter for this field:

            Field::inst( 'image' )
                ->setFormatter( 'Format::nullEmpty' )
                ->upload( ... )
    

    I've updated the example on the site with this change and it works correctly now.

    Regards,
    Allan

This discussion has been closed.