Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82109

Editor single join error

$
0
0
Hi,
I am following the tutorial and my own implementation,
1) My SELECT box is sending empty (edit/new)
2) I get a JS error:
{"id":-1,"error":"","fieldErrors":[{"name":"city_id","status":"This field is required"}],"data":[]}


editor.php >> "$this->_formData" var dump:
array
'university_name' => string 'example name' (length=5)
'sys_lookup_city' =>
array
'city_id' => string 'a6a9b81e-0e37-11e2-aed9-00ffe0621939' (length=36)

but, i add this line "$this->_formData['city_id'] = $this->_formData['sys_lookup_city']['city_id']" its works ? but its wrong ?


my js code:
$(function()
{
	var ajax_url = lookup_tables.path + '/university.php';
	
	
	editor = new $.fn.dataTable.Editor( {
		"ajaxUrl": ajax_url,
		"domTable": lookup_tables.domTable,
		"fields": [ {
				"label": "Üniversite Adı:",
				"name" : "university_name"
			}, {
                "label": "Şehir:",
                "name" : "sys_lookup_city.city_id",
				"type" : "radio"
            }
		]
	} );
	
	oThis = {
		"sDom": "Tfrtip",
		"sAjaxSource": ajax_url,
		"aoColumns": [
			{ "mData": "university_name" },
			{ 
				"mData": "sys_lookup_city.city_name",
				"sDefaultContent": "---"
			}
		],
		"oTableTools": {
			"sRowSelect": "multi",
			"aButtons": [
				{ "sExtends": "editor_create", "editor": editor },
				{ "sExtends": "editor_edit",   "editor": editor },
				{ "sExtends": "editor_remove", "editor": editor }
			]
		},
        "fnInitComplete": function ( settings, json ) {
            // Set the allowed values for the select and radio fields based on
            // what is available in the database
            editor.field('sys_lookup_city.city_id').update( json.sys_lookup_city );
        }
	};
});



my php code
<?php
require('config.php');
$_SESSION['id_col'] = 'university_id';

/*
 * Example PHP implementation used for the index.html example
 */

// DataTables PHP library
include( $dt_library_path );

// Alias Editor classes so they are easy to use
use
	DataTables\Editor,
	DataTables\Editor\Field,
	DataTables\Editor\Format,
	DataTables\Editor\Join,
	DataTables\Editor\Validate;



// Build our Editor instance and process the data coming from _POST
$editor = Editor::inst( $db, 'university_table' )
	->field(
		Field::inst( 'university_name' )->validator( 'Validate::required' ),
		Field::inst( 'city_id' )->validator( 'Validate::required' )
    )
    ->join(
        Join::inst( 'sys_lookup_city', 'object' )
            ->join( 'city_id', 'city_id' )
			->set( false )	
            ->field(
                Field::inst( 'city_id' ),
                Field::inst( 'city_name' ),
                Field::inst( 'country_id' )
            )
    );
 
// The "process" method will handle data get, create, edit and delete
// requests from the client
$out = $editor
    ->process($_POST)
    ->data();


// When there is no 'action' parameter we are getting data, and in this
// case we want to send extra data back to the client, with the options
// for the 'department' select list and 'access' radio boxes
if ( !isset($_POST['action']) ) {
    // Get department details
    $out['sys_lookup_city'] = $db
        ->select( 'sys_lookup_city', 'city_id as value, city_name as label' )
        ->fetchAll();
}



// Send it back to the client
echo json_encode( $out );

Viewing all articles
Browse latest Browse all 82109

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>