Field type plug-in stoped working after moving from editor 1.4.2 to editor 1.5.3

Field type plug-in stoped working after moving from editor 1.4.2 to editor 1.5.3

vladimirijusvladimirijus Posts: 16Questions: 4Answers: 1

I have realized the problem with field type custom made plug-in after moving from editor 1.4.2 to 1.5.3.
Initial value of field is not set, and also it is not possible to write value to the db.
Here is the plug-in code which works well in version 1.4.2:

var Editor = $.fn.DataTable.Editor;
Editor.fieldTypes.uploader = $.extend( true, {}, Editor.models.fieldType, {
    // Create the HTML mark-up needed for input and add any event handlers needed
    "create": function ( field ) {
        field._enabled = true;
        field._input = $('<div class="DTE_Field_Type_upload" >'+
                            '<input id="'+field.id+'" type="text" style="width:80%"/>'+
                            '<a class="thickbox ui-button browse" data-type="ajax" href="/ajax.php?editorID='+field.id+'">Add file</a>'+
                        '</div>')[0];
        
        this.on( 'onOpen.uploader-'+field.id, function () {
            if ( field._initSetVal ) {
                $('#'+field.id).val( field._initSetVal );
            }else{
                $('#'+field.id).val( '' )
            }
        }); 
        return field._input;    
    },     
    // Get the field value
    "get": function ( field ) {
        return $('#'+field.id).val();
    },
  
    // Set the field value
    "set": function ( field,val ) {
        if ( ! field._enabled ) {
            field._initSetVal = val;
            return;
        }
        field._initSetVal = val;
        $('input#'+field.id).val(val);
    },
  
    // Enable the field
    "enable": function ( field ) {
 
    },
  
    // Disable the field
    "disable": function ( field ) {
 
    }
} );

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    Since this is a custom field plug-in, I'd need a link to a test case showing the issue please.

    Allan

  • vladimirijusvladimirijus Posts: 16Questions: 4Answers: 1
    edited December 2015

    You can take a look at example at http://backend.front.rs/editor1.5.3/list.php

    Fill out the field "file" and try to add/update, then refresh page.

    Since this is just an example, file manager is not included (not important for this example).

    It looks that the problem is somewhere on relation editor - jquery lib.

    This is postgres sql, and also search is case sensitive which also should be changed.

    Vladimir

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    When I click the "Add file" button I get an error shown in my browser's console:

    GET http://backend.front.rs/editor1.5.3/list.php&random=1449057931030 404 (Not Found)

    A modal window is shown which is just an empty white box.

    Allan

  • vladimirijusvladimirijus Posts: 16Questions: 4Answers: 1

    Please just write down something in field "file" and try to add/update. Then refresh page and take a look at field "file" again.

    I have explained before that file manager, opened in modal window is not important for this example.

    Vladimir

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin
    Answer ✓

    It looks like the issue is due to how the get and set functions operate, plus the fact that you have a dot (.) in your field name - top_banners.file.

    I would suggest using the $.fn.dataTable.Editor.safeId() method to handle this case. If you read the description of that method it explains what the issue is in your custom plug-in and how to handle it.

    Allan

  • vladimirijusvladimirijus Posts: 16Questions: 4Answers: 1

    Thank you Allan,

    This solved the problem related to the plug-in.

This discussion has been closed.