Uncaught TypeError: editor.file is not a function

Uncaught TypeError: editor.file is not a function

jlujanjlujan Posts: 9Questions: 3Answers: 0
edited April 2021 in Editor

hi i am trying to load an image and display it but i get the following error:
Uncaught TypeError: editor.file is not a function

I would like to know in which js file this function is.
NOTE: I see that if you save the image to the database and the file uploads to the folder.

var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        "ajax": "Ajax/Staff",
        "table": "#example",
        "fields": [
        {"label": "Titulo:","name": "Titulo" }, { "label": "Autor:",  "name": "Autor" }, {
                "label": "Editorial:",
                "name": "Editorial"
            }, {"label": "Nro Pag:","name": "paginas"
            }, { "label": "Año:", "name": "anio"
            }, { "label": "Forrado:","name": "Forrado", type:  "radio",
                options: [
                    { label: "SI", value: "SI" },
                    { label: "NO",  value: "NO" }  ],
                def: "NO"
            }, {
                "label": "Observacion:",
                "name": "Observacion"
            }, {
                label: "Image:",
                name: "image",
                type: "upload",
                display: function ( file_id ) {
                    return '<img src="'+editor.file( 'files', file_id ).web_path+'"/>';
                },
                clearText: "Clear",
                noImageText: 'No image'
            }
        ]
    } );

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    My guess is that you have another assignment to the variable editor somewhere else on your page?

    Change:

    editor = new $.fn.dataTable.Editor( {

    to be:

    var editor = new $.fn.dataTable.Editor( {
    

    and drop the var editor; on the first line.

    If that doesn't fix it, can you show me the full Javascript for your page, or better yet, a link to your page.

    Thanks,
    Allan

  • jlujanjlujan Posts: 9Questions: 3Answers: 0
    edited April 2021

    Allan shipping link:
    35.217.117.165/auth/login

    credentials:
    [retracted]

    Regards,
    Jose Lujan

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Ah - thank you! You are using a really old version of Editor - 1.5.4, which was released back in 2015.

    What to do is to assign your DataTable to a variable:

    var table = $('#example').DataTable( {
    

    and then change editor.file( to be table.file( and it should work. The file() method use to be on the DataTable, but I changed it around 1.6 I think.

    Allan

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Btw - I don't see an Editor license on your account. Could you confirm which address was used to purchase it, and I'll get your account linked up correctly.

    Allan

  • jlujanjlujan Posts: 9Questions: 3Answers: 0

    thanks alan this is fantastic!

    Regarding the license, download it as a trial.
    Now I am evaluating buying because it seems very good to me.

    Lujan

This discussion has been closed.