advmultiselect

A place for users and developers of the Xataface to discuss and receive support.

advmultiselect

Postby Babs » Fri Oct 23, 2009 5:19 am

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
Babs
 
Posts: 11
Joined: Wed Oct 14, 2009 4:13 am

Postby shannah » Mon Oct 26, 2009 2:17 pm

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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Babs » Tue Oct 27, 2009 2:51 am

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!
Babs
 
Posts: 11
Joined: Wed Oct 14, 2009 4:13 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 24 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved