Hi,
I make a zend_element_date but I'd like to know if it is seen from the point
of conception.
In my element date I have added a parameter specific:
setCalendar true or false for a display jscalendar right zend text element.
that you think, is this the right way to add specific parameters?
I did not deliberately added parameters in these options as they appear in
the html code.
in my controller :
$date_publication = $this->createElement('date',
'date_publication');
$date_publication->setLabel($this->_translateController->_('date_publication'))
->setDescription('Format : "' . $format['short'] . '"')
->addValidator($validatorDate)
->setRequired(true)
->setCalendar(true)
->setValue($this->initData->date_publication)
-------------------------------------
class Pyxis_Form_Element_Date extends Zend_Form_Element_Xhtml
{
public $helper = 'formElementDate';
protected $_spec = array ('calendar' => false);
public function setSpec($spec)
{
$this->_spec = $spec;
return $this;
}
public function getSpec()
{
return $this->_spec;
}
public function setCalendar($bool)
{
$this->_spec['calendar'] = (boolean) $bool;
return $this;
}
public function setHour($bool)
{
$this->_spec['withHour'] = (boolean) $bool;
return $this;
}
}
-------------------------------------
class Zend_View_Helper_FormElementDate extends Zend_View_Helper_FormElement
{
public function formElementDate($name, $value = null, $attribs = null,
$options = null, $spec = null)
{
/*$filterDbToDate = new Pyxis_Filter_DbToDate();
$value = $filterDbToDate->filter($value);*/
$xhtml = $this->view->formText($name, $value, array_merge($attribs,
array('maxlength' => 10)));
if (!empty($spec['calendar'])) {
$xhtml .= '
<a href="javascript:void(0)" id="calendarLink_' . $name . '"><img src="' .
$this->view->baseUrl . '/images/calendar.png" alt="" id="calendar_' . $name
. '" /></a>
<script type="text/javascript">
//<![CDATA[
Calendar.setup({
inputField : "'. $name . '", // id of the input field
ifFormat : "%d/%m/%Y", // format of the input field
showsTime : true, // will display a time selector
button : "calendar_' . $name . '", // trigger for the calendar (button ID)
singleClick : true, // double-click mode
step : 1 // show all years in drop-down boxes (instead of every other year
as default)
});
//]]>
</script>';
}
return $xhtml;
}
}
thanks,
samuel