Select - display name, and store value:
Select - display name, and store value:
Hi,
I have the following editor array:
[["NameA",1],["NameB", 2]]
Created by a loader function that I use in the editor like:
var editor;
$(document).ready(function() {
editor = new $.fn.dataTable.Editor({
ajax: "server_data.php",
table: "#example1",
fields: [{
label: "ObjectName",
name: "ObjectName",
type: "select",
ipOpts: loader()
}
}]
});
The server data file is:
Editor::inst( $db, 'mytable', 'id' )
->fields(
Field::inst( 'ObjectName' )
)
->process( $_POST )
->json();
I think it ouputs the label and not the value somehow. I must store the id (ie ObjectId), instead of the Name.
Can I use setValue and somehow get the post array and reference the 2nd item? ...ex:
Editor::inst( $db, 'mytable', 'id' )
->fields(
Field::inst( 'ObjectName' )
->setValue( $_POST['ObjectName'][2] )
)
->process( $_POST )
->json();
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi,
Are you able to modify
loader()
to return an object for each item in the list (rather than array) withlabel
andvalue
properties? If you can't another option is to putloader()
into a closure function that would do that formatting for you. That then will ensure that Editor uses the correct elements for the aspects you expect.Regards,
Allan
Hi,
First off, thanks for an outstanding product.
My loader function does already output label and value (I think):
My get_object.php outputs the arrays:
[["NameA",1],["NameB",2]]
I think I've followed the cookbook, but I'm not sure...
Thanks for the extra info. So if you inspect the
select
element when it is visible, does it have the options and tables that you would expect? Thevalue
attribute from each<option>
is what will be submitted to the server and what Editor will attempt to write to the database.Allan