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.

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!


  • allanallan Posts: 61,041Questions: 1Answers: 9,955 Site admin

    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:

    $editor = Editor::inst( $db, 'users' )
    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::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::inst( 'manager.first_name', 'first_name' ),
    Field::inst( 'manager.last_name', 'last_name' )

    (the only change is to add `, 'manager_id'` ).

    And the Javascript to use `manager_id` for the Editor manager field - i.e.:

    "label": "Manager:",
    "name": "manager_id",
    "type": "select"

    This fix will be in the next release.

  • 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
    < "name": "manager_id",
    > "name": "manager",
    $ diff joinSelf.php joinSelf.orig
    < Field::inst( 'manager', 'manager_id' )->validator( 'Validate::required' )
    > Field::inst( 'manager' )->validator( 'Validate::required' )
    Can you help?
  • allanallan Posts: 61,041Questions: 1Answers: 9,955 Site admin
    In fnInitComplete you also need to use `manager_id` :

    editor.field('manager_id').update( json.userList );

    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?

  • 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.