passing back the value of a Select Field from a Lookup Table

passing back the value of a Select Field from a Lookup Table

rainbatrainbat Posts: 3Questions: 0Answers: 0
edited March 2014 in Editor
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

Replies

  • rainbatrainbat Posts: 3Questions: 0Answers: 0
    ok, i found a workaound, or maybe event the way it should be done:

    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]
  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    You are defining the parameter to be submitted as: `"name": "rbs_ticket_category.id",` - which is wh it is being submitted in that format. If you want to submit it as `category_id` , use that as the name :-). If the data is not available from that parameter (although I presume this is join field, and the data for both is identical?) you could use the `fields.data` option to specify a different data source parameter.

    Regards,
    Allan
  • rainbatrainbat Posts: 3Questions: 0Answers: 0
    Thanks for your answer ! But when I enter "category_id" as the name, then the PullDown is not pupulated anymore ... something i didn't get yet
  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    > But when I enter "category_id" as the name, then the PullDown is not populated anymore

    Presumably you are using an `field().update()` call in fnInitComplete to populate it? You need to also update the field name there.

    Allan
This discussion has been closed.