Editor single join error
Editor single join error
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:
[code]{"id":-1,"error":"","fieldErrors":[{"name":"city_id","status":"This field is required"}],"data":[]}[/code]
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:
[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 );
}
};
});
[/code]
my php code
[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 );
[/code]
I am following the tutorial and my own implementation,
1) My SELECT box is sending empty (edit/new)
2) I get a JS error:
[code]{"id":-1,"error":"","fieldErrors":[{"name":"city_id","status":"This field is required"}],"data":[]}[/code]
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:
[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 );
}
};
});
[/code]
my php code
[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 );
[/code]
This discussion has been closed.
Replies
Allan
For now, we couldn't provide you a external link. The main problem is when we open edit or create window on th fly, user select a city from select control the press ok but our code doesn't insert into the database. We have put var_dump query and wee see that the insert query which datatable generates doens't include city_id column. If we change the select control type to textbox, we realized that it put city_id column into the query. Is there anything special in use of select control?
http://i.imm.io/Onrn.png
Is your `json.sys_lookup_city` field complete and is it correctly populating the radio (or select) input? What values are being submitted to the server ('Post' tab in your Firebug screenshot)?
Allan
[code]
"name" : "city_id",
[/code]
Does it then work?
Allan