Upload with append fielddata

Upload with append fielddata

Andreas S.Andreas S. Posts: 164Questions: 56Answers: 3

Is it possible to send with the upload some fielddata with them and if the upload is success the modal windows close automatically? I read a Okt. 17 post that this is not possible but in the manual i read about ajaxdata with the append function.
I'm not sure what is now correct.
Is anywhere a example about ajaxdata and the append function?

Andreas

Answers

  • allanallan Posts: 50,842Questions: 1Answers: 7,620 Site admin

    It sounds like uploadXhrSuccess is the event you want here. It will trigger when the upload is complete, and you could call submit() if you then want to immediately submit and close the form.

    Allan

  • Andreas S.Andreas S. Posts: 164Questions: 56Answers: 3

    Is it possible to close the windows after upload?

    Andreas

  • Andreas S.Andreas S. Posts: 164Questions: 56Answers: 3

    I need with the upload at the same time more Data about the file. For example File Description. The API of the Java Serverscript need all Data before the store the file and Data. A modify with edit is not possible, that is a security rule.
    My first idea the upload should start with the submit button, but I did not find something about this. Now I try find out how can I send some more fields with the file upload. The preUpload is my event, but how did I add the form fields to the submission

    Andreas

  • mowaxmowax Posts: 12Questions: 2Answers: 0

    I'm also interested in that. I need to add a security nonce to the upload. On submit i can add it on "preSubmit". But this seems not to work on "preUpload".
    It seems not possible to append an extra ajax field then?

  • allanallan Posts: 50,842Questions: 1Answers: 7,620 Site admin

    How have you configured the Editor please? You can use ajax.data as a function and that will add information to the data to send to the server, including for upload.

    Allan

  • mowaxmowax Posts: 12Questions: 2Answers: 0

    Hallo Allan,

    The following works on 'preSubmit':

    editor.on( 'preSubmit', function ( e, data, action ) {
    
              data.tbl_action = action;
              data.action = "article_table_handler";
              data.security = ajax.security;
    } );
    

    But this is not called when uploading an image. So i tried on 'preUpload'. That is called, but there the above scheme is not working:

    editor.on( 'preUpload', function ( e, fieldName, file, data) {
    
              data.tbl_action = action;
              data.action = "article_table_handler";
              data.security = ajax.security;
    } );
    

    So my temporary solution is, to change the datatables.editor.js around line 4222 and append the data there:

    data.append( 'tbl_action', 'upload' );
    data.append( 'action', 'article_table_handler' );
    

    Just, for testing. But it worked. My problem is now, how to get this done in my own table scripts.

    Also, for 'upload', "processData" needs to be set to false, but needs to be true on read, edit, delete, create.

    I tried:

    editor = new $.fn.dataTable.Editor( {
    
            table: "#table",
            ajax: {
                url: ajax.ajax_url,
                upload: {
                     processData: false,
                     contentType: false
                }
                edit: {
                     processData: true,
                     contentType: true
                }
            },
    .
    .
    .
    

    But this is not working - then ajax is not being sent at all.

  • allanallan Posts: 50,842Questions: 1Answers: 7,620 Site admin

    So i tried on 'preUpload'. That is called, but there the above scheme is not working:

    It wouldn't no - preUpload is the correct event to use for this, but as noted there the data parameter is a FormData object. For that you need to use its append method rather than adding as you would with object notation for a plain object.

    Allan

Sign In or Register to comment.