modify Data with preSubmit for Editor REST

modify Data with preSubmit for Editor REST

matissgmatissg Posts: 63Questions: 15Answers: 0
edited June 2017 in Free community support

I'm a bit stuck with Editor REST implementation. Below I'm trying to modify data passed to server with preSubmit something like this:

// Editor code...

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
      ajax: {
          create: {
              type: 'POST',
              url:  '/strongbolt/user_groups',
          }
     // edit, remove actions follow...

      },
      table: "#user_groups_table",
      template: '#user_groups_form',
      display: "details",
      idSrc: "id",
      fields: [ {
              name: "name"
          }, {
              name: "description"
          }, {
              type: "checkbox",
              name: "users[].id",
              optionsPair: {
                label: 'name',
                value: 'id'
              }
            }, {
              type: "checkbox",
              name: "roles[].id",
              optionsPair: {
                label: 'name',
                value: 'id'
              }
            }
      ]
    } );

    var fname = editor.field( 'name' );
    var fdescription = editor.field( 'description' );
    var fusers = editor.field( 'users[].id' );
    var froles = editor.field( 'roles[].id' );
    editor.on( 'preSubmit', function ( e, data, action ) {
      if(action === "create"){
       data.data = {"strongbolt_user_group":{"name": fname, "description": fdescription, "users": fusers, "roles": froles}};
       data.dataType = "json";
      }
    } );
// more code

At the moment nothing happens when I click on "Create" button - obviously I'm doing something wrong here.

What should I be changing, to make my Ajax Create action to work, please?
Thank you!

This discussion has been closed.