Page 1 of 1

advmultiselect

PostPosted: Fri Oct 23, 2009 5:19 am
by Babs
Hi,

I need some help about advmultiselect.
I've added a transient field (type advmultiselect) in the field.ini of my table, and I want to use the items selected in a trigger function.

How to do that ?

Thanks in advance!

Babs

PostPosted: Mon Oct 26, 2009 2:17 pm
by shannah
In the beforeSave() or afterSave() trigger you can check the values that have been inserted as a result of this field.

e.g.
Code: Select all
function beforeSave(&$record){
    print_r($record->val('my_field'));
    exit;
}


Once you see how the data has been encoded, you can do with it as you please. (I'm giving your the fishing pole on this one because I don't have any handy examples to show what the data will look like...). Once you've done this you might think of posting some of this back to the forum as it could be interesting to others in the community.

Best regards

Steve

PostPosted: Tue Oct 27, 2009 2:51 am
by Babs
Hi,

Thank you Steve.

I've modified the code in Formtool/advmultiselect.php in order to take relationships into account (same option as checkboxes):

Code: Select all
if ( @$field['vocabulary'] )
{
     $options =& Dataface_FormTool::getVocabulary($record, $field);
}
     else if ( isset($field['relationship']) )
{
     $relationship =& $record->_table->getRelationship($field['relationship']);
     $options = $relationship->getAddableValues($record);
     //print_r($options);
     //exit();
}


the "print_r" you suggested gives:

Code: Select all
array([1]=>id=1, [2]=>id=2, ...)


"id" is the name of the primary index of my table. So we just have to do this:

Code: Select all
function beforeSave(&$record)
{
     $result = $record->val('po');
     foreach ($result as $id)
     {
          echo substr($id, 3)."  ";
     }
     exit();
}


to display the ids of the selected items.

Thank you for helping!