public function testCanRenderTextDelimiters()
 {
     $element = new DateSelect('foo');
     $element->setShouldCreateEmptyOption(true);
     $element->setShouldRenderDelimiters(true);
     $markup = $this->helper->__invoke($element, \IntlDateFormatter::LONG, 'pt_BR');
     // pattern === "d 'de' MMMM 'de' y"
     $this->assertStringMatchesFormat('%a de %a de %a', $markup);
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function getInputSpecification()
 {
     $inputSpec = parent::getInputSpecification();
     $inputSpec['filters'][] = ['name' => 'DateSelect', 'options' => ['null_on_empty' => !!$this->shouldCreateEmptyOption()]];
     if ($date = $this->getMinDate()) {
         $inputSpec['validators'][] = ['name' => 'GreaterThan', 'options' => ['messages' => [Validator\GreaterThan::NOT_GREATER_INCLUSIVE => 'The date ' . 'must be not earlier than %min% inclusive'], 'messageVariables' => ['min' => ['abstractOptions' => 'fmt']], 'min' => $date->format('Y-m-d'), 'fmt' => $this->format($date), 'inclusive' => true, 'break_chain_on_failure' => true]];
     }
     if ($date = $this->getMaxDate()) {
         $inputSpec['validators'][] = ['name' => 'LessThan', 'options' => ['messages' => [Validator\LessThan::NOT_LESS_INCLUSIVE => 'The date ' . 'must be not later than %max% inclusive'], 'messageVariables' => ['max' => ['abstractOptions' => 'fmt']], 'max' => $date->format('Y-m-d'), 'fmt' => $this->format($date), 'inclusive' => true, 'break_chain_on_failure' => true]];
     }
     return $inputSpec;
 }
 public function getForm(array $holidayType)
 {
     if (!$this->form) {
         $hidId = new Hidden();
         $hidId->setName('calendarId');
         $cboType = new Select();
         $cboType->setName('type')->setLabel('Type')->setAttribute('class', 'form-control')->setEmptyOption('-- Choose Types --')->setValueOptions($holidayType);
         $maxYear = date('Y', time()) + 10;
         $datePicker = new DateSelect('date');
         $datePicker->setValue(new \DateTime('now'))->setShouldRenderDelimiters(false)->setMinYear(2011)->setMaxYear($maxYear)->setLabel('Date')->setDayAttributes(array('class' => 'date-control', 'id' => 'dayCombo'))->setMonthAttributes(array('class' => 'date-control', 'id' => 'monthCombo'))->setYearAttributes(array('class' => 'date-control', 'id' => 'yearCombo'));
         $txtTitle = new Text();
         $txtTitle->setName('title')->setLabel('Title')->setAttribute('class', 'form-control')->setAttribute('placeholder', 'Title');
         $form = new Form();
         $form->setAttributes(array('class' => 'form-horizontal', 'role' => 'form'));
         $form->add($hidId);
         $form->add($cboType);
         $form->add($datePicker);
         $form->add($txtTitle);
         $this->form = $form;
     }
     return $this->form;
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public function getInputSpecification()
 {
     $spec = parent::getInputSpecification();
     $spec['filters'] = array(array('name' => 'Callback', 'options' => array('callback' => function ($date) {
         // Convert the date to a specific format
         if (is_array($date)) {
             $date = array_filter($date);
             if ($date) {
                 $date = $date['year'] . '-' . $date['month'] . '-' . $date['day'];
             } else {
                 $date = '';
             }
         }
         return $date;
     })));
     return $spec;
 }
Example #5
0
 /**
  * @expectedException \Zend\Form\Exception\InvalidArgumentException
  */
 public function testThrowsOnInvalidValue()
 {
     $element = new DateSelectElement();
     $element->setValue('hello world');
 }
Example #6
0
 /**
  * Prepare the form element (mostly used for rendering purposes)
  *
  * @param  FormInterface $form
  * @return mixed
  */
 public function prepareElement(FormInterface $form)
 {
     parent::prepareElement($form);
     $name = $this->getName();
     $this->hourElement->setName($name . '[hour]');
     $this->minuteElement->setName($name . '[minute]');
     $this->secondElement->setName($name . '[second]');
 }
Example #7
0
 public function testConstructAcceptsDayAttributes()
 {
     $sut = new DateSelectElement('dateSelect', array('day_attributes' => array('class' => 'test')));
     $dayAttributes = $sut->getDayAttributes();
     $this->assertEquals('test', $dayAttributes['class']);
 }