Editor dropdown box with composed field

Editor dropdown box with composed field

fabioberettafabioberetta Posts: 74Questions: 23Answers: 4

Dear all,

I am trying to set up an editor that allows to have a selector (dropdown menu) like in this example.

http://editor.datatables.net/examples/plug-ins/fieldPlugin.html

In the "options" of the dropdows I need to put a combination of 2 fields (first_name + last_name) coming from the database.

I do not find any simple example on how to do it. Can you help?

ty
f

This question has accepted answers - jump to:

Answers

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    If that select is supposed to update the data, how would you parse the selected option to apply it to separate fields?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Hi,

    How are you currently populating the list of options? Are you using the Field->options() method? If so, what you would need to do is provide a closure function that performs the concatenation that you are looking for. There is an example of that available here - click the "Server script" tab below the table and have a look at lines 27-42.

    If that select is supposed to update the data, how would you parse the selected option to apply it to separate fields?

    Presumably this is just the label and not the value so only output formatting is required.

    Allan

  • fabioberettafabioberetta Posts: 74Questions: 23Answers: 4

    Hi Allan,

    thanks, this is exactly what I needed.

    One more thing. How do I set the where clause?

    This comes from your example:

    $userList = $db->selectDistinct( 'users', 'id, first_name, last_name', null, 'first_name ASC' );
    

    I have to filter the table with a clause like account_id = $_SESSION['account_id']. How should I set the where clause?

    ty
    f

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    The Database->selectDistinct() method allows an option where array to be passed in. So you might use:

    $userList = $db->selectDistinct(
      'users',
      'id, first_name, last_name',
      [ 'account_id' => $_SESSION['account_id'] ],
      'first_name ASC'
    );
    

    Allan

  • fabioberettafabioberetta Posts: 74Questions: 23Answers: 4

    And it worked perfectly!

    Thanks,
    f

This discussion has been closed.