]> git.mjollnir.org Git - moodle.git/commitdiff
new method hardFreezeAllVisibleExcept
authorjamiesensei <jamiesensei>
Mon, 28 May 2007 00:46:11 +0000 (00:46 +0000)
committerjamiesensei <jamiesensei>
Mon, 28 May 2007 00:46:11 +0000 (00:46 +0000)
lib/formslib.php

index 627a2e9d30a63dc820b8cb9dc000c2b416d00b61..421547cb33a7a8a15d240dcb55a363b5a78808ab 100644 (file)
@@ -1337,7 +1337,39 @@ function validate_' . $this->_formName . '(frm) {
             return PEAR::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Nonexistant element(s): '" . implode("', '", array_keys($elementList)) . "' in HTML_QuickForm::freeze()", 'HTML_QuickForm_Error', true);
         }
         return true;
-    } // end func hardFreeze
+    }
+    /**
+     * This function also removes all previously defined rules.
+     *
+     * @param    array   $elementList       array or string of element(s) not to be frozen
+     * @since     1.0
+     * @access   public
+     * @throws   HTML_QuickForm_Error
+     */
+    function hardFreezeAllVisibleExcept($elementList)
+    {
+        $elementList = array_flip($elementList);
+        foreach (array_keys($this->_elements) as $key) {
+            $name = $this->_elements[$key]->getName();
+            $type = $this->_elements[$key]->getType();
+
+            if ($type == 'hidden'){
+                // leave hidden types as they are
+            } elseif (!isset($elementList[$name])) {
+                $this->_elements[$key]->freeze();
+                $this->_elements[$key]->setPersistantFreeze(false);
+
+                // remove all rules
+                $this->_rules[$name] = array();
+                // if field is required, remove the rule
+                $unset = array_search($name, $this->_required);
+                if ($unset !== false) {
+                    unset($this->_required[$unset]);
+                }
+            }
+        }
+        return true;
+    }
    /**
     * Tells whether the form was already submitted
     *