Error in the Example Code?
Error in the Example Code?
Hi all,
I think I have found a mistake in one of the examples. See link below.
http://editor.datatables.net/release/DataTables/extras/Editor/examples/joinSelf.html
When I start editing an entry in the example,the values stored in the selectbox are not selected. It's always only the first entry of the selectbox active. I just got the exact same problem/error. What can I do to change that?
Thanks a lot!
I think I have found a mistake in one of the examples. See link below.
http://editor.datatables.net/release/DataTables/extras/Editor/examples/joinSelf.html
When I start editing an entry in the example,the values stored in the selectbox are not selected. It's always only the first entry of the selectbox active. I just got the exact same problem/error. What can I do to change that?
Thanks a lot!
This discussion has been closed.
Replies
You are absolutely correct - there is an error int he example - thanks for pointing it out. The problem was that the PHP effectively had two fields which it was outputting as `manager` and the second one was 'winning' This meant that there was no reference to the manager id, thus the select element could not be correctly assigned a value on edit.
The fix is to change the PHP to this:
[code]
$editor = Editor::inst( $db, 'users' )
->field(
Field::inst( 'id' )->set( false ),
Field::inst( 'first_name' )->validator( 'Validate::required' ),
Field::inst( 'last_name' )->validator( 'Validate::required' ),
Field::inst( 'manager', 'manager_id' )->validator( 'Validate::required' )
)
->join(
Join::inst( 'users', 'object' ) // Read from 'users' table
->aliasParentTable( 'manager' ) // i.e. FROM users as manager
->name( 'manager' ) // JSON / POST field
->join( 'id', 'manager' ) // Join parent `id`, to child `manager`
->set( false ) // Used for read-only (change the 'manager' on the parent to change the value)
->field(
Field::inst( 'manager.first_name', 'first_name' ),
Field::inst( 'manager.last_name', 'last_name' )
)
);
[/code]
(the only change is to add `, 'manager_id'` ).
And the Javascript to use `manager_id` for the Editor manager field - i.e.:
[code]
{
"label": "Manager:",
"name": "manager_id",
"type": "select"
}
[/code]
This fix will be in the next release.
Regards,
Allan
Specifically, I made the following changes:
$ diff joinSelf.html joinSelf.orig
32c32
< "name": "manager_id",
---
> "name": "manager",
and
$ diff joinSelf.php joinSelf.orig
27c27
< Field::inst( 'manager', 'manager_id' )->validator( 'Validate::required' )
---
> Field::inst( 'manager' )->validator( 'Validate::required' )
Can you help?
[code]
editor.field('manager_id').update( json.userList );
[/code]
That might be the issue (sorry, full solution wasn't posted before). If it isn't that, can you link me to the page you are working on in its current state so I can debug it?
Allan
I am having trouble in my own attempt to implement the technique. If it continues, I'll be back.
Meantime, thanks again (and for the products)!