How to access data field in "Create New Entry" window

How to access data field in "Create New Entry" window

e8416o8e8416o8 Posts: 25Questions: 9Answers: 1
edited June 2016 in Editor

I found this was asked by several people but I could not get it work even though I tried all of suggestions.
When trying to access each field, it is displayed as undefined on console even though I can see the correct data with either

 console.log( data );  // Display data

or

 alert(JSON.stringify(data));  // Display data

Fields are defined in fields section with id as suggested as follows:

        fields: [{
                label: "Payer ID:",
                id:    "payerID",
                name:  "payerID"
            }, {
                label: "Payer Name:",
                id:    "payerName",
                name:  "payerName"

           other fields

            }, {
                label: "Termination:",
                id:    "term",
                name:  "term",
                type:  "date"
            }
        ]

This is the code excerpt trying to access each field:

    editor.on( 'preSubmit', function ( e, data, action ) {
      var xmlhttp = new XMLHttpRequest();
      if (action == "create") {
        alert ("preSubmit---create");
     
        console.log( data );  // I can see data correctly
        alert(JSON.stringify(data));  //  I can see data correctly
        
        var payerID = data.payerID;  // suggested reference to each field
        var payerID2 = data.payerID;
        var payerName = data.payerName ;
        var rateSched = data.rateSchedule;
        var groupID = data.groupID ;
        var eff = data.eff ;
        var term = data.term;
        
        console.log("payerID="+payerID);   // each field shows as undefined
        console.log("payerName="+payerName);
        console.log("rateSchedule="+rateSched);
        console.log("groupID="+groupID);
        console.log("effective="+eff);
        console.log("termination="+term);

Example object

Object {action: "create", data: Object}
action:"create"
data
:
Object
0:Object
   eff:"2016-06-03"
   groupID:"ff"
   insCo:"dd"
   insType:"ee"
   payerID:"aa"
   payerName:"bb"
   rateSchedule:"cc"
   term:"2016-06-04"

Thanks,
Karan

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

Answers

  • e8416o8e8416o8 Posts: 25Questions: 9Answers: 1

    I got it working. Thanks.

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Thanks for posting back - good to hear you have it working now.

    For anyone else reading this thread you need to loop over the data parameter in the submitted data object as of Editor 1.5. In order to support multi-row editing, the submitted data format supports multiple rows being submitted.

    Allan

This discussion has been closed.