getDecorator('HtmlTag'))) { $htmlTag->setOption('tag', 'td'); } /** @var $label \Zend_Form_Decorator_Label*/ if (($label = $element->getDecorator('Label'))) { $label->setTag('td'); } }; foreach (['Start', 'End'] as $prefix) { $this->addElement( 'date', $name . $prefix . 'Date', $getElementOptions($name . $prefix . 'Date', ['label' => $prefix . ' Date']) ); $this->addElement( 'time', $name . $prefix . 'Time', $getElementOptions($name . $prefix . ' Time', ['label' => $prefix . ' Time', 'emptyOptions' => true]) ); $updateElementDecorators($this->getElement($name . $prefix . 'Date')); $updateElementDecorators($this->getElement($name . $prefix . 'Time')); } $startDate = $this->getElement($name . 'StartDate'); $endDate = $this->getElement($name . 'EndDate'); $endDate->isRequired() && $endDate->addValidator( 'Compare', true, [ 'callback' => [$startDate, 'getValue'], 'operator' => '>=', 'messages' => $endDate->getLabel() . ' shouldn\'t be lower than ' . $startDate->getLabel() ] ); $startTime = $this->getElement($name . 'StartTime'); $endTime = $this->getElement($name . 'EndTime'); $endTime->isRequired() && $endTime->addValidator( 'Callback', true, [ 'options' => [[$startDate, 'getValue'], [$startTime, 'getValue'], [$endDate, 'getValue']], 'callback' => function ($value, $context, $startDateCallback, $startTimeCallback, $endDateCallback) { $startDate = call_user_func($startDateCallback); $startTime = call_user_func($startTimeCallback); $endDate = call_user_func($endDateCallback); return $startDate . ' ' . $startTime < $endDate . ' ' . $value; }, 'messages' => $endTime->getLabel() . ' should be greater than ' . $startTime->getLabel() ] ); $this->addDisplayGroup( [ $name . 'StartDate', $name . 'StartTime', $name . 'EndDate', $name . 'EndTime', ], $name . 'DateTimeRange' ); $group = $this->getDisplayGroup($name . 'DateTimeRange'); $group->getDecorator('FormElements')->setOption( 'wrappers', [ [ 'decorators' => [['HtmlTag', ['tag' => 'tr']]], 'elements' => [$name . 'StartDate', $name . 'StartTime'] ], [ 'decorators' => [['HtmlTag', ['tag' => 'tr']]], 'elements' => [$name . 'EndDate', $name . 'EndTime'] ] ] ); $group->getDecorator('HtmlTag')->setOption('tag', 'table'); if (array_key_exists('label', $options)) { $group->getDecorator('Fieldset')->setLegend($options['label']); } /** @var $groupWrapper \Qs_Form_Decorator_DtDdWrapper*/ $groupWrapper = $group->getDecorator('DtDdWrapper'); $groupWrapper->setDdAttrib('class', 'date-time-range-group'); if (array_key_exists('label', $options)) { //$groupWrapper->setOption('label', $options['label']); } return $this; } }