Home » HTML » HTML_Common2 » Bug #10191
[patch] add disabled/class methods to HTML_QuickForm_element
Details
| Request #10191 | [patch] add disabled/class methods to HTML_QuickForm_element |
|---|---|
| Submitted | 2007-02-26 15:38 UTC |
| From | greg at mtechsolutions dot ca |
| Assigned | avb |
| Status | Closed |
| Package | HTML_Common2 |
| PHP Version | Irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2007-02-26 15:38 UTC] greg at mtechsolutions dot ca
Description:
------------
This adds setDisabled(), getDisabled(), setClass(), getClass(), addClass(), removeClass() to the element object.
(originally available at http://freepbx.org/trac/changeset/3813)
Test script:
---------------
Index: /freepbx/branches/quickform/amp_conf/htdocs/admin/common/HTML/QuickForm/element.php
===================================================================
--- /freepbx/branches/quickform/amp_conf/htdocs/admin/common/HTML/QuickForm/element.php (revision 3578)
+++ /freepbx/branches/quickform/amp_conf/htdocs/admin/common/HTML/QuickForm/element.php (revision 3813)
@@ -316,4 +316,122 @@
return $this->_label;
} //end func getLabel
+
+ // }}}
+ // {{{ setDisabled()
+ /**
+ * Sets whether an input is disabled
+ *
+ * @param bool $disabled Whether the field is disabled or not
+ * @since 1.0
+ * @access public
+ * @return void
+ */
+ function setDisabled($disabled)
+ {
+ if (!$disabled) {
+ $this->removeAttribute('disabled');
+ } else {
+ $this->updateAttributes(array('disabled'=>'disabled'));
+ }
+ } //end func setDisabled
+
+ // }}}
+ // {{{ getDisabled()
+ /**
+ * Gets whether an input is disabled
+ *
+ * @param bool $disabled Whether the field is disabled or not
+ * @since 1.0
+ * @access public
+ * @return void
+ */
+ function getDisabled($disabled)
+ {
+ return $this->getAttribute('disabled');
+ } //end func getDisabled
+
+ // }}}
+ // {{{ setClass()
+ /**
+ * Sets the class
+ *
+ * @param mixed $class A string or array indicating the class(es) to set
+ * @since 1.0
+ * @access public
+ * @return void
+ */
+ function setClass($class)
+ {
+ if (is_array($class)) {
+ $class = implode(' ',$class);
+ }
+ $this->updateAttributes(array('class'=>$class));
+ } //end func setClass
+
+ // }}}
+ // {{{ addClass()
+ /**
+ * Sets whether a checkbox is disabled
+ *
+ * @param bool $disabled Whether the field is disabled or not
+ * @since 1.0
+ * @access public
+ * @return void
+ */
+ function addClass($class)
+ {
+ if (!is_array($class)) {
+ $class = array($class);
+ }
+
+ $curclass = $this->getClass();
+ foreach ($class as $c) {
+ if (!in_array($c, $curclass)) {
+ $curclass[] = $c;
+ }
+ }
+ $this->setClass($class);
+ } //end func addClass
+
+ // }}}
+ // {{{ removeClass()
+ /**
+ * Sets whether a checkbox is disabled
+ *
+ * @param bool $disabled Whether the field is disabled or not
+ * @since 1.0
+ * @access public
+ * @return void
+ */
+ function removeClass($class)
+ {
+ if (!is_array($class)) {
+ $class = array($class);
+ }
+
+ $curclass = $this->getClass();
+ foreach ($class as $c) {
+ if (in_array($c, $curclass)) {
+ $idx = array_search($c, $curclass);
+ unset($curclass[$idx]);
+ }
+ }
+ $this->setClass($class);
+ } //end func removeClass
+
+ // }}}
+
+ // {{{ getClass()
+ /**
+ * Sets whether a checkbox is disabled
+ *
+ * @since 1.0
+ * @access public
+ * @return array
+ */
+ function getClass()
+ {
+ return explode(' ',$this->getAttribute('class'));
+ } //end func getClass
// }}}