Error in the Example Code?

Error in the Example Code?

thdoubleuthdoubleu Posts: 8Questions: 0Answers: 0
edited April 2013 in Editor
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!

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Hi,

    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
  • jm8675jm8675 Posts: 3Questions: 0Answers: 0
    Hi. I was looking at this joinSelf example and made the two changes you suggested above, but it appears more broken now. Namely the 'select' menu in the 'Edit' popup is an empty list and the JavaScript error console shows: TypeError: 'undefined' is not an object (evaluating 'fieldConf.type').
    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?
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    In fnInitComplete you also need to use `manager_id` :

    [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
  • jm8675jm8675 Posts: 3Questions: 0Answers: 0
    That fixed it, thanks.

    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)!
  • jm8675jm8675 Posts: 3Questions: 0Answers: 0
    Got my situation working (double self-join manager Id, changer Id). Thanks.
This discussion has been closed.