Editor single join error

Editor single join error

ahmetziahmetzi Posts: 4Questions: 0Answers: 0
edited December 2012 in Editor
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]

Replies

  • allanallan Posts: 61,635Questions: 1Answers: 10,092 Site admin
    Are you able to give us a link please? The principle of what you have got looks fine. What is the JS error you are getting?

    Allan
  • ahmetziahmetzi Posts: 4Questions: 0Answers: 0
    Hi 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?
  • ahmetziahmetzi Posts: 4Questions: 0Answers: 0
    And this is the firebug javascript error output

    http://i.imm.io/Onrn.png
  • allanallan Posts: 61,635Questions: 1Answers: 10,092 Site admin
    When you say `select` - do you mean `radio` as in your code above? Either way it should work okay as it is submitted as a string.

    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
  • ahmetziahmetzi Posts: 4Questions: 0Answers: 0
    http://i.imm.io/OoSF.png
  • allanallan Posts: 61,635Questions: 1Answers: 10,092 Site admin
    Ah okay - so it's submitting `sys_lookup_city.city_id` (because that's the data source you've initialised Editor with), but the PHP is expecting just `city_id` - i.e. not from the join. If you change your Editor initialisation to:

    [code]
    "name" : "city_id",
    [/code]

    Does it then work?

    Allan
This discussion has been closed.