upload File

upload File

Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

I have a problem with the upload file and submit() function. After the successfully upload the submit should send all editor fields to update the database. The Problem is, that the file id are not send with the submit function to the server. If i do not automatically send the form with the submit() function ( click on the Form button) the file id would be send to the server.

the form field:

{
                label: 'ranking.csv:',
                name: 'fileId',
                type: 'upload',
                dragDrop: true,
                clearText: 'Remove file',
                display: function( fileId ) {
                    console.log( eEdit.file( 'paevent', fileId ).fileName );
                    return eEdit.file( 'paevent', fileId ).fileName;
                }
            }

hier my part

    eEdit.on( 'postCreate postEdit postRemove uploadXhrSuccess', function( event, data ) {
        if( 'uploadXhrSuccess' == event.type ) {
            
            
            this.submit();
        } else {
            paevent.ajax.reload( null, false );
        }
    } );

the server sends after the upload request following json string:

{"files":{"paevent":{"15":{"filename":"lm-salzburg-rd1.xlsx","web_path":"\/files\/lm-salzburg-rd1.xlsx"}}},"upload":{"id":15}}

Where is my problem?

Andreas

Answers

  • allanallan Posts: 61,734Questions: 1Answers: 10,110 Site admin

    The upload.XhrSuccess is triggered too early - it is fired off when the file upload is completed and before the returned data has been processed by Editor. Instead try listening for upload.editor. It doesn't bubble though, so you would need to listen on the input element, which you can get with field().input().

    Regards,
    Allan

  • Andreas S.Andreas S. Posts: 207Questions: 73Answers: 4

    I did not understand the second part of your messages. I should listen on the input field, but where should I do this?

  • allanallan Posts: 61,734Questions: 1Answers: 10,110 Site admin
    editor.field('myUploadField').input().on('upload.editor', function () {
      ...
    } );
    

    Allan

This discussion has been closed.