passing back the value of a Select Field from a Lookup Table
passing back the value of a Select Field from a Lookup Table
Hey Guys,
think i'm turning nuts here:
http://team.apartments-swiss-star.ch/
You can edit a row, i correctly populates the DropDown for Category.
If i hit save, then the following data is submitted back to the server:
[code]
action:edit
table:
id:row_6
data[id]:6
data[caption]:doch doch
data[rbs_ticket_category][id]:29
[/code]
but for the Editor PHP Server Side it should look like:
[code]
action:edit
table:
id:row_6
data[id]:6
data[caption]:doch doch
data[category_id]:29
[/code]
[code]
var editor;
jQuery(document).ready(function() {
editor = new jQuery.fn.dataTable.Editor( {
"ajaxUrl": "wp-content/plugins/rbs-core/rbs-server.php",
"domTable": "#rbs_ticket",
"fields": [ {
"label": "id:",
"name": "id"
}, {
"label": "caption:",
"name": "caption"
}, {
"label": "category_id:",
"dataProps" : "data[category_id]",
"name": "rbs_ticket_category.id",
"type": "select"
}
]
} );
[/code]
and on the php server side:
[code]
include( "lib/DataTables.php" );
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Join,
DataTables\Editor\Validate;
$editor = Editor::inst( $db, 'rbs_ticket' )
->field(
Field::inst( 'id' )->validator( 'Validate::required' ),
Field::inst( 'caption' )->validator( 'Validate::required' ),
Field::inst( 'category_id' )->validator( 'Validate::required' )
)
->join(
Join::inst( 'rbs_ticket_category', 'object' )
->join( 'category_id', 'id' )
->field(
Field::inst( 'caption' )
)
);
$out = $editor
->process( $_POST )
->data();
if ( !isset($_POST['action']) ) {
$out['rbs_ticket_category'] = $db
->select( 'rbs_ticket_category', 'id as value, caption as label' )
->fetchAll();
}
echo json_encode( $out );
[/code]
What am I doing wrong ? It simply missed the binding back to the column of the parent table ...
Thanks for any help, Dominique
think i'm turning nuts here:
http://team.apartments-swiss-star.ch/
You can edit a row, i correctly populates the DropDown for Category.
If i hit save, then the following data is submitted back to the server:
[code]
action:edit
table:
id:row_6
data[id]:6
data[caption]:doch doch
data[rbs_ticket_category][id]:29
[/code]
but for the Editor PHP Server Side it should look like:
[code]
action:edit
table:
id:row_6
data[id]:6
data[caption]:doch doch
data[category_id]:29
[/code]
[code]
var editor;
jQuery(document).ready(function() {
editor = new jQuery.fn.dataTable.Editor( {
"ajaxUrl": "wp-content/plugins/rbs-core/rbs-server.php",
"domTable": "#rbs_ticket",
"fields": [ {
"label": "id:",
"name": "id"
}, {
"label": "caption:",
"name": "caption"
}, {
"label": "category_id:",
"dataProps" : "data[category_id]",
"name": "rbs_ticket_category.id",
"type": "select"
}
]
} );
[/code]
and on the php server side:
[code]
include( "lib/DataTables.php" );
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Join,
DataTables\Editor\Validate;
$editor = Editor::inst( $db, 'rbs_ticket' )
->field(
Field::inst( 'id' )->validator( 'Validate::required' ),
Field::inst( 'caption' )->validator( 'Validate::required' ),
Field::inst( 'category_id' )->validator( 'Validate::required' )
)
->join(
Join::inst( 'rbs_ticket_category', 'object' )
->join( 'category_id', 'id' )
->field(
Field::inst( 'caption' )
)
);
$out = $editor
->process( $_POST )
->data();
if ( !isset($_POST['action']) ) {
$out['rbs_ticket_category'] = $db
->select( 'rbs_ticket_category', 'id as value, caption as label' )
->fetchAll();
}
echo json_encode( $out );
[/code]
What am I doing wrong ? It simply missed the binding back to the column of the parent table ...
Thanks for any help, Dominique
This discussion has been closed.
Replies
by hooking into the pre_submit hook i manually copy the parameter :
json.data.category_id = json.data.rbs_ticket_category.id;
Saturday Evening Solution ? But his should be automatically right ?
[code]
var editor;
jQuery(document).ready(function() {
editor = new jQuery.fn.dataTable.Editor( {
"ajaxUrl": "wp-content/plugins/rbs-core/rbs-server.php",
"domTable": "#rbs_ticket",
"fields": [ {
"label": "id:",
"name": "id"
}, {
"label": "caption:",
"name": "caption"
}, {
"label": "category_id:",
"name": "rbs_ticket_category.id",
"type": "select"
}
],
"events": {
"onPreSubmit": function ( json, data ){
json.data.category_id = json.data.rbs_ticket_category.id;
}
}
} );
[/code]
Regards,
Allan
Presumably you are using an `field().update()` call in fnInitComplete to populate it? You need to also update the field name there.
Allan