Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.3.1

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 OS:
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 10 - 9 = ?

 
 [2007-02-26 15:38 UTC] greg at mtechsolutions dot ca (Greg MacLellan)
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 // }}}

Comments

 [2007-02-26 20:11 UTC] avb (Alexey Borzov)
Moving feature request to HTML_QuickForm2 package. I doubt we'll ever implement setDisabled() / getDisabled(), we are trying to get rid of bloated APIs, but methods for working with 'class' attribute may be interesting, considering microformats and such.
 [2009-09-26 15:15 UTC] avb (Alexey Borzov)
-Status: Open +Status: Assigned -Package: HTML_QuickForm2 +Package: HTML_Common2 -Assigned To: +Assigned To: avb
I will add addClass(), removeClass() and hasClass() to HTML_Common2, the other stuff is not that useful.
 [2009-09-27 12:26 UTC] avb (Alexey Borzov)
-Status: Assigned +Status: Closed
Implemented in release 2.0.0RC1