Re: DB_DataObject FormBuilder

From: Date: Sat, 06 Mar 2004 13:14:58 +0000
Subject: Re: DB_DataObject FormBuilder
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-11132@lists.php.net to get a copy of this message
David Thunman wrote:
Now I bumped in to a problem creating select menu items where I want the label text of an option to be built up from two different cell values in the related table. In my case they are "tablename.last_name" and "tablename.first_name" ehich I#d like to concatenate into one string. By default, I think, the formbuilder class uses the first collumn after the primary key from the related table to create the option label text(?).
Nope, you can define which field will be used to render the entry by either putting this into your dataobject.ini: [DB_DataObject_FormBuilder] select_display_field = Description ...or, you can override this setting by defining a similarly-named property in the class that represents the table you want to display: var $select_display_field = "Some_Other_Description";
Is there an easy way to define this in an ini file or do I have to hack the formbuilder.class file to for this?
Currently, there is no way to do this without some tweaking. In the rare occasions I need something like this, I just use the preGenerateForm() method and simply define the selectbox element as I please before FormBuilder takes action. You do it in the class from which you want to build the form: function preGenerateForm(&$fb) {
    $options = array();
    $related = DB_DataObject::factory('DataObject_RelatedTable');
    $related->query('SELECT id, CONCAT(fieldOne,fieldTwo) AS field');
    while ($related->fetch()) {
        $options[$related->id] = $related->field;
    }
    unset($related);
    $box = HTML_QuickForm::createElement('select','related_id',
                                         'My related Table, $options);
    $this->preDefElements['related_id'] = $box;
} To automate things like this in the future, it might be nice to add another optional property with which you can define an SQL snippet which is used for getting the field when displaying it in a selectbox... or does anyone have a better idea? CU Markus

« previous php.pear.general (#11132) next »