ExpressionEngine / ExpressionEngine

ExpressionEngine is a flexible, feature-rich, free open-source content management platform that empowers hundreds of thousands of individuals and organizations around the world to easily manage their web site.
https://expressionengine.com
Other
458 stars 125 forks source link

Existing files cleared on Channel Form submission #646

Closed chrisdaviesweb closed 3 years ago

chrisdaviesweb commented 3 years ago

Submitting a channel form via AJAX where an entry is being 'edited' and contains a 'file grid' field, causes any existing files to be cleared.

Submitting the exact same form without AJAX, works correctly. Existing files are NOT cleared.

It is possible to replicate this, using a very basic channel, containing a 'file grid' field:

{exp:channel:form channel="channel_name" return="/somewhere" json="yes" entry_id="1"}

    <input type="text" name="title" id="title" value="{title}">
    <input type="text" name="url_title" id="url_title" value="{url_title}">

    {field:my_file_grid_field}

    <input type="submit" />

{/exp:channel:form}

To simplify, I have tested with a basic AJAX submission using jQuery Form Plugin (http://malsup.com/jquery/form/)

$('form#cform').on('submit', function (e) {
    e.preventDefault();
    $('form#cform').ajaxSubmit(function() { 
        console.log('submitted');
    });
});

Expression Engine 6 beta 3 PHP 7.4 MySQL 5.7

ops-andy commented 3 years ago

@chrisdaviesweb can you confirm this only happens if you load the channel form and make no changes and then submit? I can replicate it in that manner. However, If I load the channel form, add another row to the file grid with an image, it doesn't seem to erase previous entries for me. It's a bug either way, but just making sure we're seeing similar results.

ops-andy commented 3 years ago

also noting this happens in EE5.3 as well.

chrisdaviesweb commented 3 years ago

@ops-andy Just checked and thats the same here. It's only if the field isn't modified that the files are wiped on save.

intoeetive commented 3 years ago

When file upload is involved, AJAX calls need to be somewhat more complex.

This example works fine, no files are lost