Stop Editor Update From Using Placeholder Values

Stop Editor Update From Using Placeholder Values

gforstergforster Posts: 40Questions: 19Answers: 1

Debug - http://debug.datatables.net/ureped

I have a few "Selects" in my Editor Field. Instead of leaving a value NULL, it is attempting to update the MySQL db with the placeholder value. Is there a way to mitigate this?

Answers

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    Can you show me how you are initialising Editor please? The debugger trace does have that information in it, but it is a nightmare to find (something I'm working on!).

    Allan

  • gforstergforster Posts: 40Questions: 19Answers: 1
    edited December 2016

    No problem Here's the javascript portion:

    <script type="text/javascript" language="javascript" class="init">
             var editor; 
     
             $(document).ready(function() {
                 editor = new $.fn.dataTable.Editor( {
                     ajax: "servers_table.php",
                     table: "#example",
                     fields: [ {
                             label: "Hostname",
                             name: "VOLUMES.server_id",
                             placeholder: "Select the Hostname"
                         }, {
                             label: "Development Level",
                             name: "VOLUMES.devlvl_id",
                             type: "select",
                             placeholder: "What is the Dev Level"
                         }, {
                             label: "OS:",
                             name: "VOLUMES.os_id",
                             type: "select",
                             placeholder: "Select An Operating System"
                         }, {
                             label: "Location:",
                             name: "VOLUMES.location_id",
                             type: "select",
                             placeholder: "Select A Location"
                         }, {
                             label: "Volume:",
                             name: "Volume.name",
                             type: "select",
                             placeholder: "Select the Volume Name"
                         }, {
                             label: "Services:",
                             name: "COMPONENTS[].id",
                             type: "checkbox"
                         }, {
                             label: "Model Number:",
                             name: "VOLUMES.model_id",
                             type: "select",
                             placeholder: "Select the Volume Name"
      }, {
                             label: "Group:",
                             name: "VOLUMES.srvrgrp_id",
                             type: "select",
                             placeholder: "Select the Group"
                         }, {
                             label: "description",
                             name: "SERVERS.description"
                         }
                     ]
                  } ); 
                 $('#example').DataTable( {
                     dom: "Bfrtip",
                     paging: false,
                     scrollY: 500,
                         ajax: {
                             url: "servers_table.php",
                             type: 'POST'
                     },
                     columns: [
                         { data: "SERVERS.name" },
                         { data: "VOLUMES.name"},
                         { data: "DEVLVL.name" },
                         { data: "OS.name"},
                         { data: "LOCATION.name"},
                         { data: "COMPONENTS", render:"[,].name"},
                         { data: "MODEL.name"},
                         { data: "SRVRGRP.name"},
                         // Description Is Last For Sake Of Readability
                         { data: "VOLUMES.description" }
                     ],
                     select: true,
                     buttons: [
                         { extend: "create", editor: editor },
                         { extend: "edit",   editor: editor },
                         { extend: "remove", editor: editor },
                         {
                             extend: 'collection',
                             text: 'Export',
                             buttons: [
                                     'copy',
                                     'excel',
                                     'csv',
                                     'pdf',
                                     'print'
                             ]
                      }
                     ]
                 } );
         } );
     </script>
    

    and here's the php:

     <?php
     
     // DataTables PHP library
     include( "php/DataTables.php" );
     
     // Alias Editor classes so they are easy to use
     use
         DataTables\Editor,
         DataTables\Editor\Field,
         DataTables\Editor\Format,
         DataTables\Editor\Mjoin,
         DataTables\Editor\Options,
         DataTables\Editor\Upload,
         DataTables\Editor\Validate;
     
     // Build our Editor instance and process the data coming from _POST
     Editor::inst( $db, 'VOLUMES' )
         ->fields(
             Field::inst( 'VOLUMES.id' ),
             Field::inst( 'VOLUMES.name' )
                 ->validator( 'Validate::dbValues' ),
             Field::inst( 'VOLUMES.server_id' )
                 ->options( Options::inst()
                     ->table( 'SERVERS' )
                     ->value( 'id' )
                     ->label( 'name' )
                 )
                 ->validator( 'Validate::dbValues' ),
             Field::inst( 'SERVERS.name' ),
             Field::inst( 'VOLUMES.devlvl_id' )
                 ->options( Options::inst()
                     ->table( 'DEVLVL' )
                     ->value( 'id' )
                     ->label( 'name' )
                 )
                 ->validator( 'Validate::dbValues' ),
             Field::inst( 'DEVLVL.name' ),
             Field::inst( 'VOLUMES.os_id' )
                 ->options( Options::inst()
                     ->table( 'OS' )
                     ->value( 'id' )
                     ->label( 'name' )
                 )
                 ->validator( 'Validate::dbValues' ),
             Field::inst( 'OS.name' ),
             Field::inst( 'VOLUMES.location_id' )
                 ->options( Options::inst()
                     ->table( 'LOCATION' )
                     ->value( 'id' )
                     ->label( 'name' )
                 )
                 ->validator( 'Validate::dbValues' ),
    Field::inst( 'LOCATION.name' ),
             Field::inst( 'VOLUMES.model_id' )
                 ->options( Options::inst()
                     ->table( 'MODEL' )
                     ->value( 'id' )
                     ->label( 'name' )
                 )
                 ->validator( 'Validate::dbValues' ),
             Field::inst( 'MODEL.name' ),
             Field::inst( 'VOLUMES.srvrgrp_id' )
                 ->options( Options::inst()
                     ->table( 'SRVRGRP' )
                     ->value( 'id' )
                     ->label( 'name' )
                 )
                 ->validator( 'Validate::dbValues' ),
             Field::inst( 'SRVRGRP.name' ),
             Field::inst( 'VOLUMES.description' )
         )
         // Normal Left Join Implementation
         ->leftJoin( 'DEVLVL', 'VOLUMES.devlvl_id', '=', 'DEVLVL.id' )
         ->leftJoin( 'OS', 'VOLUMES.os_id', '=', 'OS.id' )
         ->leftJoin( 'LOCATION', 'VOLUMES.location_id', '=', 'LOCATION.id' )
         ->leftJoin( 'SERVERS', 'VOLUMES.server_id', '=', 'SERVERS.id' )
         ->leftJoin( 'MODEL', 'VOLUMES.model_id', '=', 'MODEL.id' )
         ->leftJoin( 'SRVRGRP', 'VOLUMES.srvrgrp_id', '=', 'SRVRGRP.id' )
         // One To Many or Many To Many Joins Use Mjoin Class
         ->join(
             Mjoin::inst( 'COMPONENTS' )
                 ->link( 'VOLUMES.id', 'HOSTSVCS.volume_id' )
                 ->link( 'COMPONENTS.id', 'HOSTSVCS.component_id' )
                 ->fields(
                     Field::inst( 'id' )
                         ->options( Options::inst()
                             ->table( 'COMPONENTS' )
                             ->value( 'id' )
                             ->label( 'name' )
                         ),
                     Field::inst( 'name' )
                 )
         )
         ->process( $_POST )
         ->json();
    
This discussion has been closed.