Browse files

Allow to specify attributes per element

  • Loading branch information...
1 parent 4dab8ba commit ac1464e04e551ff764130b03ff7dc3a25d28ede7 @bakura10 bakura10 committed Sep 12, 2012
Showing with 95 additions and 1 deletion.
  1. +40 −0 library/Zend/Form/Element/DateSelect.php
  2. +55 −1 library/Zend/Form/Element/MonthSelect.php
View
40 library/Zend/Form/Element/DateSelect.php
@@ -38,6 +38,24 @@ public function __construct($name = null, $options = array())
}
/**
+ * Accepted options for DateSelect (plus the ones from MonthSelect) :
+ * - day_attributes: HTML attributes to be rendered with the day element
+ *
+ * @param array|\Traversable $options
+ * @return DateSelect
+ */
+ public function setOptions($options)
+ {
+ parent::setOptions($options);
+
+ if (isset($options['day_attributes'])) {
+ $this->setDayAttributes($options['day_attributes']);
+ }
+
+ return $this;
+ }
+
+ /**
* @return Select
*/
public function getDayElement()
@@ -46,6 +64,28 @@ public function getDayElement()
}
/**
+ * Set the day attributes
+ *
+ * @param array $dayAttributes
+ * @return DateSelect
+ */
+ public function seDayAttributes(array $dayAttributes)
+ {
+ $this->dayElement->setAttributes($dayAttributes);
+ return $this;
+ }
+
+ /**
+ * Get the day attributes
+ *
+ * @return array
+ */
+ public function getDayAttributes()
+ {
+ return $this->dayElement->getAttributes();
+ }
+
+ /**
* @param mixed $value
* @return void|\Zend\Form\Element
*/
View
56 library/Zend/Form/Element/MonthSelect.php
@@ -80,16 +80,26 @@ public function __construct($name = null, $options = array())
/**
* Accepted options for DateSelect:
+ * - month_attributes: HTML attributes to be rendered with the month element
+ * - year_attributes: HTML attributes to be rendered with the month element
* - min_year: min year to use in the year select
* - max_year: max year to use in the year select
*
* @param array|\Traversable $options
- * @return DateSelect
+ * @return MonthSelect
*/
public function setOptions($options)
{
parent::setOptions($options);
+ if (isset($options['month_attributes'])) {
+ $this->setMonthAttributes($options['month_attributes']);
+ }
+
+ if (isset($options['year_attributes'])) {
+ $this->setYearAttributes($options['year_attributes']);
+ }
+
if (isset($options['min_year'])) {
$this->setMinYear($options['min_year']);
}
@@ -122,6 +132,50 @@ public function getYearElement()
}
/**
+ * Set the month attributes
+ *
+ * @param array $monthAttributes
+ * @return MonthSelect
+ */
+ public function setMonthAttributes(array $monthAttributes)
+ {
+ $this->monthElement->setAttributes($monthAttributes);
+ return $this;
+ }
+
+ /**
+ * Get the month attributes
+ *
+ * @return array
+ */
+ public function getMonthAttributes()
+ {
+ return $this->monthElement->getAttributes();
+ }
+
+ /**
+ * Set the year attributes
+ *
+ * @param array $yearAttributes
+ * @return MonthSelect
+ */
+ public function setYearAttributes(array $yearAttributes)
+ {
+ $this->yearElement->setAttributes($yearAttributes);
+ return $this;
+ }
+
+ /**
+ * Get the year attributes
+ *
+ * @return array
+ */
+ public function getYearAttributes()
+ {
+ return $this->yearElement->getAttributes();
+ }
+
+ /**
* @param int $minYear
* @return MonthSelect
*/

0 comments on commit ac1464e

Please sign in to comment.