Datatables Editor - Bug with upload?
Datatables Editor - Bug with upload?
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
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 anullEmpty
formatter available to be used which will writenull
to the database when an empty string is submitted.Long story short, we need to use the
nullEmpty
formatter for this field:I've updated the example on the site with this change and it works correctly now.
Regards,
Allan