Re: DOFB how to register custom element

From: Date: Tue, 25 Jan 2005 18:59:11 +0000
Subject: Re: DOFB how to register custom element
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17152@lists.php.net to get a copy of this message
On Tue, 25 Jan 2005 19:12:02 +0100, Alexander Petri <alex.petri@gmx.de> wrote: > i want to use a custom element for my application > hardcoded, my form looks like this: > > $form = new HTML_QuickForm(); > $form->registerElementType('htmlarea', 'HTML/QuickForm/htmlarea.php', > 'HTML_QuickForm_htmlarea'); > > $options = array('url' => '../js/htmlarea/'); > $attributes = array('rows' => 25, 'cols' => 80); > $config = array('width' => '300px', 'height' => > '300px','statusBar'=>true,'pageStyle'=>'@import > url(../css/style.css);'); > $options2 = $options; > $options2['config'] = $config; > > $form->addElement('htmlarea', 'text2', 'HTMLArea2', $options2, > $attributes); > $form->addElement('submit', '__submit__', 'Testing'); > > $htmlarea2 = &$form->getElement('text2'); > $htmlarea2->registerPlugin('ContextMenu'); > $htmlarea2->registerPlugin('TableOperations'); > $htmlarea2->registerPlugin('DynamicCSS'); > $htmlarea2->setToolbar(array('fontname', > 'fontsize','DynamicCSS-class', > 'linebreak', > 'bold', 'italic', 'underline','separator', > "justifyleft", "justifycenter", "justifyright", > "justifyfull",'separator', > "outdent", "indent", "separator", > "createlink",'htmlmode')); > > print $form->toHtml(); > > but how can i include this in my DO? > > function preGenerateForm(&$fb) { > > $this->fb_preDefElements['news_text'] = > HTML_QuickForm::createElement('textarea', > > 'news_text','Newstext',array("cols"=>"45","rows"=>"8")); > > should be > $this->fb_preDefElements['news_text'] = > HTML_QuickForm::createElement('htmlarea', ....)); > > could someone help me? > If you want to convert all of your textareas to htmlareas, use elementTypeMap (you should do this in the FB, not the DO). $fb = DB_DataObject_FormBuilder::create($do)l $fb->elementTypeMap['longtext'] = 'htmlarea'; If you need to set those extra options on each element, I would suggest you do it in your QF element class by default. If those options are element specific, do it in postGenerateForm. function postGenerateForm(&$form) { $el =& $form->getElement('textField'); $el->registerPlugin(...); } -- Justin Patrin

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