cvs: pear /DB_DataObject_FormBuilder FormBuilder.php package.xml package2.xml /DB_DataObject_FormBuilder/FormBuilder QuickForm.php
/DB_DataObject_FormBuilder/FormBuilder/QuickForm SubForm.php SubFormFB.php

From: Date: Thu, 26 May 2005 23:35:31 +0000
Subject: cvs: pear /DB_DataObject_FormBuilder FormBuilder.php package.xml package2.xml /DB_DataObject_FormBuilder/FormBuilder QuickForm.php
/DB_DataObject_FormBuilder/FormBuilder/QuickForm SubForm.php SubFormFB.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-32147@lists.php.net to get a copy of this message
justinpatrin Thu May 26 19:35:31 2005 EDT Added files: /pear/DB_DataObject_FormBuilder/FormBuilder/QuickForm SubForm.php SubFormFB.php Modified files: /pear/DB_DataObject_FormBuilder FormBuilder.php package.xml package2.xml /pear/DB_DataObject_FormBuilder/FormBuilder QuickForm.php Log: linkNewValue now uses an extended SubForm QF element This allows it to actually act like a regular element, hopefully working with setDefaults, setConstants, and HTML_QuickForm_Controller

http://cvs.php.net/diff.php/pear/DB_DataObject_FormBuilder/FormBuilder.php?r1=1.178&r2=1.179&ty=u Index: pear/DB_DataObject_FormBuilder/FormBuilder.php diff -u pear/DB_DataObject_FormBuilder/FormBuilder.php:1.178 pear/DB_DataObject_FormBuilder/FormBuilder.php:1.179 --- pear/DB_DataObject_FormBuilder/FormBuilder.php:1.178 Tue May 24 14:07:59 2005 +++ pear/DB_DataObject_FormBuilder/FormBuilder.php Thu May 26 19:35:29 2005 @@ -94,7 +94,7 @@ * @author Justin Patrin <papercrane@reversefold.com> * @copyright 1997-2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version $Id: FormBuilder.php,v 1.178 2005/05/24 18:07:59 justinpatrin Exp $ + * @version $Id: FormBuilder.php,v 1.179 2005/05/26 23:35:29 justinpatrin Exp $ * @link http://pear.php.net/package/DB_DataObject_FormBuilder * @see DB_DataObject, HTML_QuickForm */ @@ -2431,21 +2431,26 @@ if ($dbOperations) { //take care of linkNewValues - if (isset($values['__DB_DataObject_FormBuilder_linkNewValue_'])) { - foreach ($values['__DB_DataObject_FormBuilder_linkNewValue_'] as $elName => $subTable) { - if ($values[$elName] == $this->linkNewValueText) { - $this->_form->_prepareForLinkNewValue($elName, $subTable); - $ret = $this->_form->_linkNewValueForms[$elName]->process(array(&$this->_form->_linkNewValueFBs[$elName], 'processForm'), false); - if (PEAR::isError($ret)) { - $this->debug('Error processing linkNewValue for '.serialize($this->_form->_linkNewValueDOs[$elName])); - return PEAR::raiseError('Error processing linkNewValue - Error from processForm: '.$ret->getMessage(), - null, - null, - null, - $this->_form->_linkNewValueDOs[$elName]); + /*if (isset($values['__DB_DataObject_FormBuilder_linkNewValue_'])) { + foreach ($values['__DB_DataObject_FormBuilder_linkNewValue_'] as $elName => $subTable) {*/ + if (isset($this->_form->_linkNewValueForms)) { + foreach (array_keys($this->_form->_linkNewValueForms) as $elName) { + $subTable = $this->_form->_linkNewValueDOs[$elName]->tableName(); + if (isset($values[$this->elementNamePrefix.'__DB_DataObject_FormBuilder_linkNewValue_'.$this->elementNamePostfix.'__'.$elName])) { + if ($values[$elName] == $this->linkNewValueText) { + //$this->_form->_prepareForLinkNewValue($elName, $subTable); + $ret = $this->_form->_linkNewValueForms[$elName]->process(array(&$this->_form->_linkNewValueFBs[$elName], 'processForm'), false); + if (PEAR::isError($ret)) { + $this->debug('Error processing linkNewValue for '.serialize($this->_form->_linkNewValueDOs[$elName])); + return PEAR::raiseError('Error processing linkNewValue - Error from processForm: '.$ret->getMessage(), + null, + null, + null, + $this->_form->_linkNewValueDOs[$elName]); + } + $subPk = $this->_form->_linkNewValueFBs[$elName]->_getPrimaryKey($this->_form->_linkNewValueDOs[$elName]); + $this->_do->$elName = $values[$elName] = $this->_form->_linkNewValueDOs[$elName]->$subPk; } - $subPk = $this->_form->_linkNewValueFBs[$elName]->_getPrimaryKey($this->_form->_linkNewValueDOs[$elName]); - $this->_do->$elName = $values[$elName] = $this->_form->_linkNewValueDOs[$elName]->$subPk; } } } http://cvs.php.net/diff.php/pear/DB_DataObject_FormBuilder/package.xml?r1=1.46&r2=1.47&ty=u Index: pear/DB_DataObject_FormBuilder/package.xml diff -u pear/DB_DataObject_FormBuilder/package.xml:1.46 pear/DB_DataObject_FormBuilder/package.xml:1.47 --- pear/DB_DataObject_FormBuilder/package.xml:1.46 Fri May 20 20:03:44 2005 +++ pear/DB_DataObject_FormBuilder/package.xml Thu May 26 19:35:29 2005 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> -<!-- $Id: package.xml,v 1.46 2005/05/21 00:03:44 justinpatrin Exp $ --> +<!-- $Id: package.xml,v 1.47 2005/05/26 23:35:29 justinpatrin Exp $ --> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package version="1.0"> <name>DB_DataObject_FormBuilder</name> @@ -31,10 +31,43 @@ </maintainer> </maintainers> <release> - <version>0.16.0</version> + <version>0.16.1</version> <state>alpha</state> - <date>2005-05-20</date> + <date>2005-05-23</date> <notes><![CDATA[ +Fixed bug #4407, addFormHeader no longer works in 0.16.0 +Fixed notices in QuickForm.php related to member vars +Added support for multiple crossLink and tripleLink elements to the same table in one form +Changed linkNewValue to use a SubForm element and a group instead of PopupSelect +Removed PopupSelect as it's no longer used + ]]></notes> + <filelist> + <dir name="/" baseinstalldir="/DB/DataObject"> + <file role="php">FormBuilder.php</file> + <dir name="FormBuilder" baseinstalldir="/DB/DataObject"> + <file role="php">QuickForm.php</file> + <dir name="QuickForm" baseinstalldir="/DB/DataObject"> + <file role="php">ElementTable.php</file> + <file role="php">SubForm.php</file> + <file role="php">SubFormFB.php</file> + </dir> + </dir> + </dir> + </filelist> + <deps> + <dep type="php" rel="ge" version="4.3.0" /> + <dep type="pkg" rel="has" optional="no">DB_DataObject</dep> + <dep type="pkg" rel="ge" version="3.2.4" optional="no">HTML_QuickForm</dep> + <dep type="pkg" rel="has" optional="yes">Date</dep> + <dep type="pkg" rel="has" optional="yes">HTML_Table</dep> + </deps> + </release> + <changelog> + <release> + <version>0.16.0</version> + <state>alpha</state> + <date>2005-05-20</date> + <notes><![CDATA[ Sorry to bring us back down to alpha, but I just changed the driver architecture. We should be back up to beta within a few releases. Changes @@ -59,28 +92,8 @@ ** Note: useCallTimePassByRef is now needed only if you use the FormBuilder parameter in the getForm callback * If you set the 'collapse' key of a crossLink array to true, the unselected crossLink records will be hidden until you click the "Show All" link beneath them. This should help a lot for large amounts of records in crossLinks. - ]]></notes> - <filelist> - <dir name="/" baseinstalldir="/DB/DataObject"> - <file role="php">FormBuilder.php</file> - <dir name="FormBuilder" baseinstalldir="/DB/DataObject"> - <file role="php">QuickForm.php</file> - <dir name="QuickForm" baseinstalldir="/DB/DataObject"> - <file role="php">ElementTable.php</file> - <file role="php">PopupSelect.php</file> - </dir> - </dir> - </dir> - </filelist> - <deps> - <dep type="php" rel="ge" version="4.3.0" /> - <dep type="pkg" rel="has" optional="no">DB_DataObject</dep> - <dep type="pkg" rel="ge" version="3.2.4" optional="no">HTML_QuickForm</dep> - <dep type="pkg" rel="has" optional="yes">Date</dep> - <dep type="pkg" rel="has" optional="yes">HTML_Table</dep> - </deps> - </release> - <changelog> + ]]></notes> + </release> <release> <version>0.15.0</version> <state>beta</state> http://cvs.php.net/diff.php/pear/DB_DataObject_FormBuilder/package2.xml?r1=1.18&r2=1.19&ty=u Index: pear/DB_DataObject_FormBuilder/package2.xml diff -u pear/DB_DataObject_FormBuilder/package2.xml:1.18 pear/DB_DataObject_FormBuilder/package2.xml:1.19 --- pear/DB_DataObject_FormBuilder/package2.xml:1.18 Fri May 20 20:03:44 2005 +++ pear/DB_DataObject_FormBuilder/package2.xml Thu May 26 19:35:30 2005 @@ -27,41 +27,22 @@ <email>norbert@php.net</email> <active>yes</active> </developer> - <date>2005-05-21</date> - <time>01:56:07</time> + <date>2005-05-27</date> + <time>01:33:30</time> <version> - <release>0.16.0</release> - <api>0.16.0</api> + <release>0.16.1</release> + <api>0.16.1</api> </version> <stability> <release>alpha</release> <api>alpha</api> </stability> <license uri="http://www.php.net/license">PHP License</license> - <notes>Sorry to bring us back down to alpha, but I just changed the driver architecture. We should be back up to beta within a few releases. - -Changes -* BC Break! The QuickForm driver no longer extends the FormBuilder main class -** This means that extended versions of FormBuilder are no longer tied to a specific driver, however -** If you have created your own FormBuilder extended class in the past you now need to alter it to -** extend DB_DataObject_FormBuilder instead of DB_DataObject_FormBuilder_QuickForm - -** If you are instantiation your FormBuilder object with &quot;new&quot; you should switch to using DB_DataObject_FormBuilder::create() - -Fixes -* validateOnProcess no longer fails when linkNewValue is used - -New Features -* There are now callback options to allow custom functions to be set for: -** preGenerateForm -** postGenerateForm -** preProcessForm -** postProcessForm -** prepareLinekdDataObject - -** Note: useCallTimePassByRef is now needed only if you use the FormBuilder parameter in the getForm callback - -* If you set the &apos;collapse&apos; key of a crossLink array to true, the unselected crossLink records will be hidden until you click the &quot;Show All&quot; link beneath them. This should help a lot for large amounts of records in crossLinks. + <notes>Fixed bug #4407, addFormHeader no longer works in 0.16.0 +Fixed notices in QuickForm.php related to member vars +Added support for multiple crossLink and tripleLink elements to the same table in one form +Changed linkNewValue to use a SubForm element and a group instead of PopupSelect +Removed PopupSelect as it&apos;s no longer used </notes> <contents> @@ -69,7 +50,8 @@ <dir name="FormBuilder"> <dir name="QuickForm"> <file baseinstalldir="/DB/DataObject" name="ElementTable.php" role="php" /> - <file baseinstalldir="/DB/DataObject" name="PopupSelect.php" role="php" /> + <file baseinstalldir="/DB/DataObject" name="SubForm.php" role="php" /> + <file baseinstalldir="/DB/DataObject" name="SubFormFB.php" role="php" /> </dir> <!-- //FormBuilder/QuickForm --> <file baseinstalldir="/DB/DataObject" name="QuickForm.php" role="php" /> </dir> <!-- //FormBuilder --> @@ -109,6 +91,44 @@ <changelog> <release> <version> + <release>0.16.0</release> + <api>0.16.0</api> + </version> + <stability> + <release>alpha</release> + <api>alpha</api> + </stability> + <date>2005-05-20</date> + <license uri="http://www.php.net/license">PHP License</license> + <notes>Sorry to bring us back down to alpha, but I just changed the driver architecture. We should be back up to beta within a few releases. + +Changes +* BC Break! The QuickForm driver no longer extends the FormBuilder main class +** This means that extended versions of FormBuilder are no longer tied to a specific driver, however +** If you have created your own FormBuilder extended class in the past you now need to alter it to +** extend DB_DataObject_FormBuilder instead of DB_DataObject_FormBuilder_QuickForm + +** If you are instantiation your FormBuilder object with &quot;new&quot; you should switch to using DB_DataObject_FormBuilder::create() + +Fixes +* validateOnProcess no longer fails when linkNewValue is used + +New Features +* There are now callback options to allow custom functions to be set for: +** preGenerateForm +** postGenerateForm +** preProcessForm +** postProcessForm +** prepareLinekdDataObject + +** Note: useCallTimePassByRef is now needed only if you use the FormBuilder parameter in the getForm callback + +* If you set the &apos;collapse&apos; key of a crossLink array to true, the unselected crossLink records will be hidden until you click the &quot;Show All&quot; link beneath them. This should help a lot for large amounts of records in crossLinks. + + </notes> + </release> + <release> + <version> <release>0.15.0</release> <api>0.15.0</api> </version> http://cvs.php.net/diff.php/pear/DB_DataObject_FormBuilder/FormBuilder/QuickForm.php?r1=1.45&r2=1.46&ty=u Index: pear/DB_DataObject_FormBuilder/FormBuilder/QuickForm.php diff -u pear/DB_DataObject_FormBuilder/FormBuilder/QuickForm.php:1.45 pear/DB_DataObject_FormBuilder/FormBuilder/QuickForm.php:1.46 --- pear/DB_DataObject_FormBuilder/FormBuilder/QuickForm.php:1.45 Wed May 25 14:01:41 2005 +++ pear/DB_DataObject_FormBuilder/FormBuilder/QuickForm.php Thu May 26 19:35:30 2005 @@ -11,7 +11,7 @@ * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @author Markus Wolff <mw21st@php.net> * @author Justin Patrin <papercrane@reversefold.com> - * @version $Id: QuickForm.php,v 1.45 2005/05/25 18:01:41 justinpatrin Exp $ + * @version $Id: QuickForm.php,v 1.46 2005/05/26 23:35:30 justinpatrin Exp $ */ require_once ('HTML/QuickForm.php'); @@ -70,6 +70,7 @@ */ var $formHeaderText; var $linkNewValue; + var $linkNewValueText; var $elementNamePrefix; var $elementNamePostfix; var $dateElementFormat; @@ -410,27 +411,39 @@ $options, array('multiple' => 'multiple')); } else { - if (isset($this->linkNewValue[$fieldName])) { - if (!HTML_QuickForm::isTypeRegistered('popupSelect')) { - HTML_QuickForm::registerElementType('popupSelect', - 'DB/DataObject/FormBuilder/QuickForm/PopupSelect.php', - 'DB_DataObject_FormBuilder_QuickForm_PopupSelect'); - } - $type = 'popupSelect'; - } else { - $type = 'select'; - } - $element =& HTML_QuickForm::createElement($this->_getQFType($type), + $element =& HTML_QuickForm::createElement($this->_getQFType('select'), $this->_fb->getFieldName($fieldName), $this->_fb->getFieldLabel($fieldName), $options); - if ($type == 'popupSelect') { - $element->setFormBuilder($this->_fb); - $element->setFieldName($fieldName); + $attr = $this->_getAttributes('select', $fieldName); + $element->updateAttributes($attr); + if (isset($this->linkNewValue[$fieldName])) { + $links = $this->_fb->_do->links(); + if (isset($links[$fieldName])) { + list($table,) = explode(':', $links[$fieldName]); + require_once('DB/DataObject/FormBuilder/QuickForm/SubFormFB.php'); + $element->addOption($this->linkNewValueText, $this->linkNewValueText); + $element->updateAttributes(array('onchange' => 'db_do_fb_'.$this->_fb->getFieldName($fieldName).'__subForm_display(this)')); + $element->updateAttributes(array('id' => $element->getName())); + $this->_prepareForLinkNewValue($fieldName, $table); + $subFormElement = HTML_QuickForm::createElement('subFormFB', + $this->_fb->getFieldName($fieldName).'__subForm', + '', + $this->_linkNewValueForms[$fieldName]); + $subFormElement->setPreValidationCallback(array(&$subFormElement, 'preValidationCallback')); + $subFormElement->linkNewValueText = $this->linkNewValueText; + $subFormElement->selectName = $this->_fb->getFieldName($fieldName); + $el =& $this->_form->addElement('hidden', $this->_fb->getFieldName($fieldName).'__subForm__displayed'); + $el->updateAttributes(array('id' => $el->getName())); + $element = HTML_QuickForm::createElement('group', + $this->_fb->getFieldName($fieldName), + $this->_fb->getFieldLabel($fieldName), + array($element, $subFormElement), + '<br/>', + false); + } } } - $attr = $this->_getAttributes('select', $fieldName); - $element->updateAttributes($attr); return $element; } @@ -451,12 +464,17 @@ */ function validateLinkNewValues($values) { $valid = true; - if (isset($values[$this->elementNamePrefix.'__DB_DataObject_FormBuilder_linkNewValue_'.$this->elementNamePostfix])) { - foreach ($values[$this->elementNamePrefix.'__DB_DataObject_FormBuilder_linkNewValue_'.$this->elementNamePostfix] as $elName => $subTable) { - if ($values[$this->elementNamePrefix.$elName.$this->elementNamePostfix] == '--New Value--') { - $this->_prepareForLinkNewValue($elName, $subTable); - if (!$this->_linkNewValueForms[$elName]->validate()) { - $valid = false; + /*if (isset($values[$this->elementNamePrefix.'__DB_DataObject_FormBuilder_linkNewValue_'.$this->elementNamePostfix])) { + foreach ($values[$this->elementNamePrefix.'__DB_DataObject_FormBuilder_linkNewValue_'.$this->elementNamePostfix] as $elName => $subTable) {*/ + if (isset($this->_linkNewValueForms)) { + foreach (array_keys($this->_linkNewValueForms) as $elName) { + $subTable = $this->_linkNewValueDOs[$elName]->tableName(); + if (isset($values[$this->elementNamePrefix.'__DB_DataObject_FormBuilder_linkNewValue_'.$this->elementNamePostfix.'__'.$elName])) { + if ($values[$this->elementNamePrefix.$elName.$this->elementNamePostfix] == '--New Value--') { + $this->_prepareForLinkNewValue($elName, $subTable); + if (!$this->_linkNewValueForms[$elName]->validate()) { + $valid = false; + } } } } @@ -485,7 +503,7 @@ $this->_linkNewValueForms[$elName] =& $this->_linkNewValueFBs[$elName]->getForm(); $this->_linkNewValueForms[$elName]->addElement('hidden', $this->elementNamePrefix.'__DB_DataObject_FormBuilder_linkNewValue_'. - $this->elementNamePostfix.'['.$elName.']', $subTable); + $this->elementNamePostfix.'__'.$elName, $subTable); } } http://cvs.php.net/co.php/pear/DB_DataObject_FormBuilder/FormBuilder/QuickForm/SubForm.php?r=1.1&p=1 Index: pear/DB_DataObject_FormBuilder/FormBuilder/QuickForm/SubForm.php +++ pear/DB_DataObject_FormBuilder/FormBuilder/QuickForm/SubForm.php <?php /** * */ require_once('HTML/QuickForm/static.php'); if ( substr(phpversion(),0,1) != 5) { if (!function_exists('clone')) { // emulate clone - as per php_compact, slow but really the correct behaviour.. eval('function clone($t) { $r = $t; if (method_exists($r,"__clone")) { $r->__clone(); } return $r; }'); } } /** * A few caveats: this element *must* be either created by a call to addElement on your main form (with the * construction parameters, not an element object) or you must call setParentForm on the element. If you * don't, the rules on the subform won't work. Here's the two usages (assuming $form is the main form * and $subForm is the sub-form): * * require_once('HTML/QuickForm/SubForm.php'); * $form->addElement('subForm', 'subFormElementName', 'Sub Form Label', $subForm); * //NOTE: with this version $subForm is now a copy in the element so changing * // $subForm now will not change the form within the element * * OR * * require_once('HTML/QuickForm/SubForm.php'); * $el =& HTML_QuickForm::createElement('subFormElementName', 'Sub Form Label', $subForm); * $el->setParentForm($form); * $form->addElement($el); * * This also uses a few hacks which access HTML_QuickForm internals which is a no-no, but it's the only * way I could get unfreeze and setPersistentFreeze to work as HTML_QuickForm doesn't implement these * functions (perhaps these should be added?). This also only works with the default QF renderer, but * it shouldn't be too hard to fix it. * * This *should* also work for subforms within subforms. ;-) * * The following are quick instructions on how to get a dynamic subform * working (i.e. a subform which is displayed / hidden by JS and * conditionally validated). * * Add a hidden field which holds when the sub form is displayed. * $form->addElement('hidden', 'subFormDisplayed'); * * Use this CSS class: * .hidden { * overflow: hidden; * visibility: hidden; * display: none; * } * * Apply that class to a div surrounding the SubForm (I use an eltered * elementTemplate for QF). You also need a link which calls the * javascript below (I've added it to the template for simplicity). * Also, only hide it if the sub form was not displayed (if the * validation fails you need to redisplay the form). * * $renderer =& HTML_QuickForm::defaultRenderer(); * $renderer->setElementTemplate(str_replace('{element}', * '<a href="javascript:void();" onclick="showSubFormElement()">Show Sub Form</a> * <div class="'.($_REQUEST['subFormDisplayed'] ? '' : 'hidden')." id="idForElementDiv">{element}</div>', * $renderer->_elementTemplate), * 'subFormElement'); * * * Add the JavaScript with the function somewhere in your code. * * <script language="javascript"> * function newCorrectiveAction() { * if(document.getElementById("idForElementDiv").className == "hidden") { * document.getElementById("idForElementDiv").className = ""; * document.getElementById("subFormDisplayed").value = "1"; * } else { * document.getElementById("idForElementDiv").className = "hidden"; * document.getElementById("subFormDisplayed").value = "0"; * } * } * </script> * * Now add the sub form element and also make sure to set up the * conditional validation. (assuming $subForm is your completed sub * form. Note that there may be reference problems here, it's best to * have the sub form finished before creating the element). * * require_once('HTML/QuickForm/SubForm.php'); * function subFormDisplayed($values) { * return $values['subFormDisplayed'] == 1; * } * $el =& HTML_QuickForm::createElement('subForm', 'subFormElement', '', $subForm); * $el->setPreValidationCallback('subFormDisplayed'); */ class HTML_QuickForm_SubForm extends HTML_QuickForm_static { var $_subForm; var $_parentForm; var $_name; var $_preValidationCallback; function HTML_QuickForm_SubForm($name=null, $label=null, $form=null) { if ($form !== null) { $this->setForm($form); } HTML_QuickForm_static::HTML_QuickForm_static($name, $label); } function setForm(&$form) { $this->_subForm =& $form; } function accept(&$renderer, $required = null, $error = null) { $this->_renderer = clone($renderer); $renderer->renderElement($this, $required, $error); } /** * renders the element * * @return string the HTML for the element */ function toHtml() { if (isset($this->_renderer)) { $this->_renderer->_html = $this->_renderer->_hiddenHtml = $this->_renderer->_groupTemplate = $this->_renderer->_groupWrap = ''; $this->_renderer->_groupElements = array(); $this->_renderer->_inGroup = false; } else { $this->_renderer = clone(HTML_QuickForm::defaultRenderer()); } $this->_renderer->setFormTemplate(preg_replace('!</?form[^>]*>!', '', $this->_renderer->_formTemplate)); $this->_subForm->accept($this->_renderer); return $this->_renderer->toHtml(); } function freeze() { parent::freeze(); $this->_subForm->freeze(); } function unfreeze() { parent::unfreeze(); foreach (array_keys($this->_subForm->_elements) as $key) { $this->_subForm->_elements[$key]->unfreeze(); } } function setPersistantFreeze($persistant = false) { parent::setPersistantFreeze($persistant); foreach (array_keys($this->subForm->_elements) as $key) { $this->_subForm->_elements[$key]->setPersistantFreeze($persistant); } } function exportValue(&$submitValues, $assoc = false) { return $this->_subForm->exportValues(); } function setParentForm(&$form) { $this->_parentForm =& $form; $this->_parentForm->addFormRule(array(&$this, 'checkSubFormRules')); $this->_ruleRegistered = true; } /** * If set, the pre validation callback will be called before the sub-form's validation is checked. * This is meant to allow the developer to turn off sub-form validation for optional forms. */ function setPreValidationCallback($callback = null) { $this->_preValidationCallback = $callback; } function checkSubFormRules($values) { if ((!isset($this->_preValidationCallback) || !is_callable($this->_preValidationCallback) || call_user_func($this->_preValidationCallback, $values)) && !$this->_subForm->validate()) { return array($this->getName() => 'Please fix the errors below'); } else { return true; } } /** * Sets this element's name * * @param string name */ function setName($name) { $this->_name = $name; } /** * Gets this element's name * * @return string name */ function getName() { return $this->_name; } /** * Called by HTML_QuickForm whenever form event is made on this element * * @param string Name of event * @param mixed event arguments * @param object calling object * @access public * @return bool true */ function onQuickFormEvent($event, $arg, &$caller) { if (is_a($caller, 'html_quickform')) { $this->setParentForm($caller); } switch ($event) { case 'updateValue': $this->_subForm->_submitValues = $caller->_submitValues; $this->_subForm->setDefaults($caller->_defaultValues); $this->_subForm->setConstants($caller->_constantValues); break; default: parent::onQuickFormEvent($event, $arg, $caller); break; } return true; } } if (class_exists('HTML_QuickForm')) { HTML_QuickForm::registerElementType('subForm', __FILE__, 'HTML_QuickForm_SubForm'); } ?> http://cvs.php.net/co.php/pear/DB_DataObject_FormBuilder/FormBuilder/QuickForm/SubFormFB.php?r=1.1&p=1 Index: pear/DB_DataObject_FormBuilder/FormBuilder/QuickForm/SubFormFB.php +++ pear/DB_DataObject_FormBuilder/FormBuilder/QuickForm/SubFormFB.php <?php require_once('DB/DataObject/FormBuilder/QuickForm/SubForm.php'); class HTML_QuickForm_SubFormFB extends HTML_QuickForm_SubForm { function preValidationCallback($values) { return isset($values[$this->getAttribute('name').'__displayed']) && $values[$this->getAttribute('name').'__displayed']; } function toHtml() { return ' <script language="javascript"> function db_do_fb_'.$this->getName().'_display(sel) { div = document.getElementById("'.$this->getName().'__div"); if(sel.value == "'.$this->linkNewValueText.'") { div.style.visibility = "visible"; div.style.display = "block"; div.style.overflow = "auto"; document.getElementById("'.$this->getName().'__displayed").value = "1"; } else { div.style.display = "none"; div.style.overflow = "hidden"; div.style.visibility = "hidden"; document.getElementById("'.$this->getName().'__displayed").value = "0"; } } </script> <div id="'.$this->getName().'__div"> '.parent::toHtml().' </div> <script language="javascript"> db_do_fb_'.$this->getName().'_display(document.getElementById("'.$this->selectName.'")); </script> '; } } if (class_exists('HTML_QuickForm')) { HTML_QuickForm::registerElementType('subFormFB', __FILE__, 'HTML_QuickForm_SubFormFB'); } ?>
« previous php.pear.cvs (#32147) next »