Cannot read property 'multiEditable' of undefined

Cannot read property 'multiEditable' of undefined

bvelasquezbvelasquez Posts: 28Questions: 7Answers: 0

I seem to keep getting this error and not sure why or how to fix it.

Console:

datatables.js:50065 Uncaught TypeError: Cannot read property 'multiEditable' of undefined
at Editor._multiInfo (datatables.js:50065)
at Editor.Field._multiValueCheck (datatables.js:45671)
at Editor.Field.multiSet (datatables.js:45473)
at Object.<anonymous> (datatables.js:49625)
at Function.each (datatables.js:383)
at Editor.Field.<anonymous> (datatables.js:49621)
at Function.each (datatables.js:383)
at Editor._edit (datatables.js:49617)
at Editor.edit (datatables.js:47565)
at _Api.action (datatables.js:52070)

No message comes up in the UI.

To duplicate, click on the new button, then I click on the edit button and the error will come up in the console. The modal window will not open. Editing multiple items - one after another - does not trigger the error. It only comes up when you switch to create a record (which works), but then the edit function will stop working.

I have tried to mark several fields as "multiEditable: false" but that doesn't seem to do anything. In the viewer I also have select restricted to single:

            "select": {
                "style": "single" // change to multiple
            },

When I look at the editor code, it points me to the following:

/**
 * Update the multi-value information display to not show redundant information
 *
 * @private
 */
Editor.prototype._multiInfo = function ()
{
    var fields = this.s.fields;
    var include = this.s.includeFields;
    var show = true;
    var state;

    if ( ! include ) {
        return;
    }

    for ( var i=0, ien=include.length ; i<ien ; i++ ) {
        var field = fields[ include[i] ];
        var multiEditable = field.multiEditable();

        if ( field.isMultiValue() && multiEditable && show ) {
            // Multi-row editable. Only show first message
            state = true;
            show = false;
        }
        else if ( field.isMultiValue() && ! multiEditable ) {
            // Not multi-row editable. Always show message
            state = true;
        }
        else {
            state = false;
        }

        fields[ include[i] ].multiInfoShown( state );
    }
};

Not sure why it goes to that function though...

Here is where the call starts:

var _buttons = DataTable.ext.buttons;


$.extend( _buttons, {
    create: {
        text: function ( dt, node, config ) {
            return dt.i18n( 'buttons.create', config.editor.i18n.create.button );
        },
        className: 'buttons-create',
        editor: null,
        formButtons: {
            label: function ( editor ) {
                return editor.i18n.create.submit;
            },
            fn: function (e) {
                this.submit();
            }
        },
        formMessage: null,
        formTitle: null,
        action: function( e, dt, node, config ) {
            var editor = config.editor;
            var buttons = config.formButtons;

            editor.create( {
                buttons: config.formButtons,
                message: config.formMessage,
                title:   config.formTitle || editor.i18n.create.title
            } );
        }
    },

    edit: {
        extend: 'selected',
        text: function ( dt, node, config ) {
            return dt.i18n( 'buttons.edit', config.editor.i18n.edit.button );
        },
        className: 'buttons-edit',
        editor: null,
        formButtons: {
            label: function ( editor ) {
                return editor.i18n.edit.submit;
            },
            fn: function (e) {
                this.submit();
            }
        },
        formMessage: null,
        formTitle: null,
        action: function( e, dt, node, config ) {
            var editor = config.editor;
            var rows = dt.rows( { selected: true } ).indexes();
            var columns = dt.columns( { selected: true } ).indexes();
            var cells = dt.cells( { selected: true } ).indexes();

            var items = columns.length || cells.length ?
                {
                    rows: rows,
                    columns: columns,
                    cells: cells
                } :
                rows;

            editor.edit( items, {
                message: config.formMessage,
                buttons: config.formButtons,
                title:   config.formTitle || editor.i18n.edit.title
            } );
        }
    },

My primary key is set to idSrc: "ItemID", which is flagged as "multiEditable: false"

In my onInitCreate function I have the following code:

            datatables_editor_detail_init.on('onInitCreate', function () {
                setTimeout(function () {

                    datatables_editor_detail_init.set("WorkDate", currentWorkingDate);

                    // Remove the ItemID field from the data on create
                    datatables_editor_detail_init.clear("ItemID");

                }, 100);
            });

and my onInitEdit:

            datatables_editor_detail_init.on('onInitEdit', function () {
                setTimeout(function () {
                    
                    datatables_editor_detail_init.set("WorkDate", currentWorkingDate);

                    // Always show Item ID on edit
                    datatables_editor_detail_init.show("ItemID");

                }, 1);
            });     

On create, the ItemID is generated automatically by the DB. Passing a null value for that field to the server will generate an error (I only have the client side editor). This is an example of the format accepted:

{
  "UserID": "username",
  "WorkDate": "2017-05-10",
  "Department": "OSP",
  "Project": "Admin",
  "Hours": "2",
  "Comments": "test"
}

and the edit will be the same, except for the "ItemID"

{
  "ItemID": 50371,
  "UserID": "username",
  "WorkDate": "2017-05-10",
  "Department": "OSP",
  "Project": "Admin",
  "Hours": "2",
  "Comments": "test - edit test"
}

After clicking the Edit button (after the New button), it just stops.
Any ideas on how to prevent the multi function from coming up?

This question has an accepted answers - jump to answer

Answers

  • bvelasquezbvelasquez Posts: 28Questions: 7Answers: 0

    Looks like I was able to resolve the issue by manipulating the submitted data instead of dynamically add() or clear() fields on edit and create.

    I don't believe the single select on the viewer or the multiEditable field option had anything to do with it.

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Hi,

    I realise you've got this resolved now, but out of interest, what version of Editor are you using?

    Thanks,
    Allan

  • bvelasquezbvelasquez Posts: 28Questions: 7Answers: 0
    • Included libraries:
    • Bootstrap 3.3.7, jQuery 2.2.4, Moment 2.13.0, jQuery Mask 1.13.4, Select2 4.0.1, Selectize 0.12.1, DataTables 1.10.13, Buttons 1.2.4, Column visibility 1.2.4, HTML5 export 1.2.4, Print view 1.2.4, Editor 1.6.1, Field type - Display 1.5.6, Field type - Mask 1.5.6, Field type - Select2 1.5.6, Field type - Selectize 1.5.6, Field type - Title 1.5.6, FixedColumns 3.2.2, FixedHeader 3.1.2, KeyTable 2.2.0, Responsive 2.1.1, Scroller 1.4.2, Select 1.2.0
      */
  • bvelasquezbvelasquez Posts: 28Questions: 7Answers: 0

    Another question along the same lines ~ is multieditable fields possible without the server addon? if so, how would I be able to modify the multiple calls?

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Yes, the multi-row editing is possible without the provided PHP or .NET libraries, but obviously whatever server-side process you are using will need the ability to handle the data submitted for multiple rows.

    The client / server interchange that Editor uses is fully documented here if you want to implement your own server-side libraries.

    Allan

This discussion has been closed.