[Editor] Immediatly submit the form after a upload is made

[Editor] Immediatly submit the form after a upload is made

tiago.fernandestiago.fernandes Posts: 13Questions: 4Answers: 0

I have a question regarding the Editor behaviour after a upload on the form is made. I wonder if you can help me with that.

I'm using the following code on the controller:

...
    
    ->join(
        Mjoin::inst( 'ficheiros' )
            ->link( 'ordens_nacional.ordem_nacional', 'ordens_files.id_ordem' )
            ->link( 'ficheiros.id', 'ordens_files.file_id' )
            ->fields(
                Field::inst( 'id' )
                    ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/ecra/uploads/editor/__ID__.__EXTN__' )
                        ->db( 'ficheiros', 'id', array(
                            'filename'    => Upload::DB_FILE_NAME,
                            'filesize'    => Upload::DB_FILE_SIZE,
                            'web_path'    => Upload::DB_WEB_PATH,
                            'system_path' => Upload::DB_SYSTEM_PATH,
                            'username' => $_GET['user']
                        ) )
                    )
            )
    )
...

I'm using the following code on the page:

...
 {
                label: "Documentos:",
                name: "ficheiros[].id",
                type: "uploadMany",
                display: function ( fileId, counter ) {
                    return '<a target="_blank" href="'+editor.file( 'ficheiros', fileId ).web_path+'">'+editor.file( 'ficheiros', fileId ).filename+'</a> <small>('+editor.file( 'ficheiros', fileId ).username+')</small>';
                },
                noFileText: 'Sem ficheiros'
            }
...

Do you think is it possible, after a upload is made, to submit or update the row immediately, without having to click on 'submit' or 'edit'?

Thank you in advance for your care.

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,944Questions: 87Answers: 416
    edited January 2020 Answer ✓

    Sure just take a look at this: https://editor.datatables.net/reference/field/upload

    Search for "Listen for an upload event" on that page and you'll find an example.

    All you would need to do is to submit your editor instance when the event occurs.

    Something like this should work:

    ....
    $( editor.field( 'image' ).input() ).on( 'upload.editor', function (e, val) {
      editor.submit();
    } );
    
This discussion has been closed.