Error on preSubmit to DB: Cannot set property 'pending' of undefined

Error on preSubmit to DB: Cannot set property 'pending' of undefined

giovanni.braccigiovanni.bracci Posts: 13Questions: 2Answers: 3
edited February 2019 in Free community support

Hi Everybody,

I cannot update DB from my custom Edit form. I got the error "Cannot set property 'pending' of undefined".

Here's the link to EXAMPLE
https://www.beppebiondi.it/example/

This is the action I am trying to do and where i get the error.
I want to modify example.pending and example.pendingTo on my DB with '0' and 'null' respectively.

    editorPending.on( 'preSubmit', function ( e, data, action ) {
        if ( action === 'edit' ) {
            scelta = editorPending.field( 'example.pending' ).val();
            if ( scelta === '1' ) { 
                data.data.example.pending = 0;
                data.data.example.pendingTo = null;
            }
            else {
                alert (scelta); 
            }
        }
    } );

See attachments for full code of Javascript and Server Side.

Please, could someone help me? I am going crazy! THANKS! :smile:

Giovanni

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

Replies

  • giovanni.braccigiovanni.bracci Posts: 13Questions: 2Answers: 3
    edited February 2019

    This is what I've done and now it seems to go successfully.
    Is it right?
    Why is "data.data.example.pending = 0;" wrong?

        editorPending.on( 'preSubmit', function ( e, data, action ) {
            // console.log("data = ", data);
            $.each(data.data, function (key, value) {
            if ( action === 'edit' ) {
                var scelta = editorPending.field( 'example.pending' ).val();
                if ( scelta === '1' ) {
                    data.data[ key ].example.pending = 0;
                    data.data[ key ].example.pendingTo = null;
                }
                else {
                    bla bla bla 
                }
            }
            } );
        } );
    
  • allanallan Posts: 62,246Questions: 1Answers: 10,211 Site admin

    Hi,

    Good to hear you've got the solution. The reason you can't just use data.data.propertyName is that Editor supports multi-row editing, so the content in data.data is actually an object - one entry for each row being edited. This approach is used even if there is only one row being edited.

    Full details of the data submitted available here.

    Before multi-row editing was introduced (1.5) then yes, what you had would have worked, but it didn't allow for multi-row editing.

    Allan

  • giovanni.braccigiovanni.bracci Posts: 13Questions: 2Answers: 3
    edited February 2019

    Thank you very much Allan!
    Can I ask you how can I avoid submitting of certain fileds I need to see in the editor but not to update in DB? This data comes from a join and I don't want to update the joined table. Is it possible?

This discussion has been closed.