public function testProvidesInputSpecificationThatIncludesValidatorsBasedOnAttributes() { $element = new DateElement('foo'); $element->setAttributes(array('inclusive' => true, 'min' => '2000-01-01', 'max' => '2001-01-01', 'step' => '1')); $inputSpec = $element->getInputSpecification(); $this->assertArrayHasKey('validators', $inputSpec); $this->assertInternalType('array', $inputSpec['validators']); $expectedClasses = array('Zend\\Validator\\Date', 'Zend\\Validator\\GreaterThan', 'Zend\\Validator\\LessThan', 'Zend\\Validator\\DateStep'); foreach ($inputSpec['validators'] as $validator) { $class = get_class($validator); $this->assertTrue(in_array($class, $expectedClasses), $class); switch ($class) { case 'Zend\\Validator\\GreaterThan': $this->assertTrue($validator->getInclusive()); $this->assertEquals('2000-01-01', $validator->getMin()); break; case 'Zend\\Validator\\LessThan': $this->assertTrue($validator->getInclusive()); $this->assertEquals('2001-01-01', $validator->getMax()); break; case 'Zend\\Validator\\DateStep': $dateInterval = new \DateInterval('P1D'); $this->assertEquals($dateInterval, $validator->getStep()); $this->assertEquals('2000-01-01', $validator->getBaseValue()); break; default: break; } } }
protected function getDateElement($name, $options) { $elementSpec = isset($options[$name]) ? $options[$name] : ''; $elementOptions = isset($elementSpec['options']) ? $elementSpec['options'] : array(); $element = new Date($name, $elementOptions); if (isset($elementSpec['attributes'])) { $element->setAttributes($elementSpec['attributes']); } return $element; }
public function testCorrectFormatPassedToDateValidator() { $element = new DateElement('foo'); $element->setAttributes(array('min' => '2012-01-01', 'max' => '2012-12-31')); $element->setFormat('d-m-Y'); $inputSpec = $element->getInputSpecification(); foreach ($inputSpec['validators'] as $validator) { switch (get_class($validator)) { case 'Zend\\Validator\\DateStep': case 'Zend\\Validator\\Date': $this->assertEquals('d-m-Y', $validator->getFormat()); break; } } }
public function getForm(array $formulaList) { if (!$this->form) { $fromDate = new Element\Date('fromDate'); $fromDate->setAttributes(array('allowPastDates' => true, 'style' => 'width:120px;', 'momentConfig' => array('format' => 'YYYY-MM-DD'))); $fromDate->setValue(date('Y-m-26', strtotime('-1 month'))); $toDate = new Element\Date('toDate'); $toDate->setAttributes(array('allowPastDates' => true, 'style' => 'width:120px;margin-left:5px;', 'momentConfig' => array('format' => 'YYYY-MM-DD'))); $toDate->setValue(date('Y-m-25', time(''))); $formula = new Element\Select(); $formula->setName('formula')->setAttribute('class', 'form-control')->setAttribute('style', 'width:200px')->setValueOptions($formulaList)->setEmptyOption('-- Choose Formula --'); $form = new Form(); $form->setAttributes(array('class' => 'form-inline', 'role' => 'form', 'id' => 'process-form')); $form->add($fromDate); $form->add($toDate); $form->add($formula); $this->form = $form; } return $this->form; }
public function init() { $customer = new Select('customer'); $customer->setAttribute('id', 'customer'); $customer->setAttribute('title', $this->translator->translate('web.form.document.customer.title')); $customer->setAttribute('class', 'form-control'); $customer->setEmptyOption($this->translator->translate('web.form.document.customer.emptyOption')); $customer->setValueOptions($this->getCustomerValues()); $customer->setLabel($this->translator->translate('web.form.document.customer.label')); $this->add($customer); $supplier = new Select('supplier'); $supplier->setAttribute('id', 'supplier'); $supplier->setAttribute('title', $this->translator->translate('web.form.document.supplier.title')); $supplier->setAttribute('class', 'form-control'); $supplier->setEmptyOption($this->translator->translate('web.form.document.supplier.emptyOption')); $supplier->setValueOptions($this->getSupplierValues()); $supplier->setLabel($this->translator->translate('web.form.document.supplier.label')); $this->add($supplier); $paymentType = new Select('paymentType'); $paymentType->setAttribute('id', 'paymentType'); $paymentType->setAttribute('title', $this->translator->translate('web.form.document.paymentMethod.title')); $paymentType->setAttribute('class', 'form-control'); $paymentType->setEmptyOption($this->translator->translate('web.form.document.paymentMethod.emptyOption')); $paymentType->setValueOptions(Document::$paymentTypes); $paymentType->setLabel($this->translator->translate('web.form.document.paymentMethod.label')); $this->add($paymentType); $vat = new Select('vat'); $vat->setAttribute('id', 'vat'); $vat->setAttribute('title', $this->translator->translate('web.form.document.vat.title')); $vat->setAttribute('class', 'form-control'); $vat->setEmptyOption($this->translator->translate('web.form.document.vat.emptyOption')); $vat->setValueOptions($this->getVatValues()); $vat->setLabel($this->translator->translate('web.form.document.vat.label')); $this->add($vat); $docDate = new Date('docDate'); $docDate->setAttributes(array('id' => 'docDate', 'type' => 'text', 'class' => 'input datepicker form-control', 'data-date-weekstart' => 1, 'data-date-format' => 'dd.mm.yyyy')); $docDate->setAttribute('title', $this->translator->translate('web.form.document.docDate.title')); $docDate->setAttribute('readonly', 'readonly'); $docDate->setAttribute('placeholder', $this->translator->translate('web.form.document.docDate.placeholder')); $docDate->setLabel($this->translator->translate('web.form.document.docDate.label')); $this->add($docDate); $supplierDocNumber = new Text('supplierDocNumber'); $supplierDocNumber->setAttribute('id', 'supplierDocNumber'); $supplierDocNumber->setAttribute('title', $this->translator->translate('web.form.document.supplierDocNumber.title')); $supplierDocNumber->setAttribute('class', 'form-control'); $supplierDocNumber->setAttribute('placeholder', $this->translator->translate('web.form.document.supplierDocNumber.placeholder')); $supplierDocNumber->setLabel($this->translator->translate('web.form.document.supplierDocNumber.label')); $this->add($supplierDocNumber); $deadlineDays = new Text('deadlineDays'); $deadlineDays->setAttribute('id', 'deadlineDays'); $deadlineDays->setAttribute('title', $this->translator->translate('web.form.document.deadlineDays.title')); $deadlineDays->setAttribute('class', 'form-control'); $deadlineDays->setAttribute('placeholder', $this->translator->translate('web.form.document.deadlineDays.placeholder')); $deadlineDays->setLabel($this->translator->translate('web.form.document.deadlineDays.label')); $this->add($deadlineDays); $delayPercent = new Text('delayPercent'); $delayPercent->setAttribute('id', 'delayPercent'); $delayPercent->setAttribute('class', 'form-control'); $delayPercent->setAttribute('title', $this->translator->translate('web.form.document.delayPercent.title')); $delayPercent->setAttribute('placeholder', $this->translator->translate('web.form.document.delayPercent.placeholder')); $delayPercent->setLabel($this->translator->translate('web.form.document.delayPercent.label')); $this->add($delayPercent); $amount = new Text('amount'); $amount->setAttribute('id', 'amount'); $amount->setAttribute('title', $this->translator->translate('web.form.document.amount.title')); $amount->setAttribute('class', 'form-control'); $amount->setAttribute('readonly', 'readonly'); $amount->setAttribute('placeholder', $this->translator->translate('web.form.document.amount.placeholder')); $amount->setLabel($this->translator->translate('web.form.document.amount.label')); $this->add($amount); $taxAmount = new Text('taxAmount'); $taxAmount->setAttribute('id', 'taxAmount'); $taxAmount->setAttribute('title', $this->translator->translate('web.form.document.taxAmount.title')); $taxAmount->setAttribute('class', 'form-control'); $taxAmount->setAttribute('readonly', 'readonly'); $taxAmount->setAttribute('placeholder', $this->translator->translate('web.form.document.taxAmount.placeholder')); $taxAmount->setLabel($this->translator->translate('web.form.document.taxAmount.label')); $this->add($taxAmount); $comment = new Textarea('comment'); $comment->setAttribute('id', 'comment'); $comment->setAttribute('title', $this->translator->translate('web.form.document.comment.title')); $comment->setAttribute('class', 'form-control'); $comment->setAttribute('cols', 15); $comment->setAttribute('rows', 4); $comment->setAttribute('placeholder', $this->translator->translate('web.form.document.comment.placeholder')); $comment->setLabel($this->translator->translate('web.form.document.comment.label')); $this->add($comment); $amountTax = new Text('amountTax'); $amountTax->setAttribute('id', 'amountTax'); $amountTax->setAttribute('title', $this->translator->translate('web.form.document.amountTax.title')); $amountTax->setAttribute('class', 'form-control'); $amountTax->setAttribute('readonly', 'readonly'); $amountTax->setAttribute('placeholder', $this->translator->translate('web.form.document.amountTax.placeholder')); $amountTax->setLabel($this->translator->translate('web.form.document.amountTax.label')); $this->add($amountTax); return $this; }
protected function generateFormElementByType($name, $type, $values = array(), $priority) { switch ($type) { case 'FILE': $elm = new Element\File(); $elm->setLabel(strtoupper($name)); break; case 'SELECT': $elm = new Element\Select($name); $elm->setLabel(strtoupper($name)); $elm->setAttribute('id', $name . '_ID'); if ($values instanceof \Traversable || is_array($values)) { $elm->setValueOptions($values); } break; case 'DATE': if (isset($option_elements['DateTimePicker']) && $option_elements['DateTimePicker']['status'] == 'enabled') { $elm = new \Zf2datatable\Form\Element\DateCalendar($name); $elm->setAttribute('id', $name . '_ID'); $elm->setAttribute('class', 'form-control'); $elm->setLabel($name); $elm->setAttribute('jsOption', $option_elements['DateTimePicker']['options']['date_js_properties']); \Zf2datatable\Form\Element\DateCalendar::setDateFormatIn($option_elements['DateTimePicker']['options']['date_format_in']); \Zf2datatable\Form\Element\DateCalendar::setDateFormatOut($option_elements['DateTimePicker']['options']['date_format_out']); } else { $elm = new Element\Date($name); $elm->setLabel(strtoupper($name)); $elm->setAttributes(array('type' => 'date')); $elm->setFormat('Y-m-d'); } break; case 'DATETIME': if (isset($option_elements['DateTimePicker']) && $option_elements['DateTimePicker']['status'] == 'enabled') { $elm = new \Zf2datatable\Form\Element\DateTimeCalendar($name); $elm->setAttribute('id', $name . '_ID'); $elm->setAttribute('class', 'form-control'); $elm->setLabel($name); $elm->setAttribute('jsOption', $option_elements['DateTimePicker']['options']['datetime_js_properties']); \Zf2datatable\Form\Element\DateTimeCalendar::setDateFormatIn($option_elements['DateTimePicker']['options']['datetime_format_in']); \Zf2datatable\Form\Element\DateTimeCalendar::setDateFormatOut($option_elements['DateTimePicker']['options']['datetime_format_out']); } else { $elm = new Element\DateTimeSelect($name); $elm->setLabel(strtoupper($name)); } break; default: $elm = new Element($name); $elm->setLabel(strtoupper($name)); $elm->setAttributes(array('type' => 'text')); break; } $elm->setOption('priority', $priority); return $elm; }
public function init() { $paymentType = new Radio('paymentType'); $paymentType->setAttribute('id', 'paymentType'); $paymentType->setAttribute('class', 'paymentType'); $paymentType->setAttribute('title', $this->translator->translate('web.form.document.paymentType.title')); $paymentType->setAttribute('required', 'required'); $paymentType->setLabel($this->translator->translate('web.form.document.paymentType.label')); $paymentType->setValueOptions(BankTransaction::$paymentTypes); $this->add($paymentType); $invoiceText = new Text('invoiceText'); $invoiceText->setAttribute('id', 'invoiceText'); $invoiceText->setAttribute('class', 'form-control')->setAttribute('placeholder', $this->translator->translate('transaction.form.invoiceText.placeholder'))->setLabel($this->translator->translate('transaction.form.invoiceText.label')); $this->add($invoiceText); $invoiceNumber = new Text('invoiceNumber'); $invoiceNumber->setAttribute('id', 'invoiceNumber'); $invoiceNumber->setAttribute('class', 'form-control')->setAttribute('readonly', 'readonly')->setAttribute('placeholder', $this->translator->translate('transaction.form.invoiceNumber.placeholder'))->setLabel($this->translator->translate('transaction.form.invoiceNumber.label')); $this->add($invoiceNumber); $invoiceId = new Text('invoiceId'); $invoiceId->setAttribute('id', 'invoiceId'); $this->add($invoiceId); $purchInvoiceText = new Text('purchInvoiceText'); $purchInvoiceText->setAttribute('id', 'purchInvoiceText'); $purchInvoiceText->setAttribute('class', 'form-control')->setAttribute('placeholder', $this->translator->translate('transaction.form.purchInvoiceText.placeholder'))->setLabel($this->translator->translate('transaction.form.purchInvoiceText.label')); $this->add($purchInvoiceText); $purchInvoiceNumber = new Text('purchInvoiceNumber'); $purchInvoiceNumber->setAttribute('id', 'purchInvoiceNumber'); $purchInvoiceNumber->setAttribute('class', 'form-control')->setAttribute('readonly', 'readonly')->setAttribute('placeholder', $this->translator->translate('transaction.form.purchInvoiceNumber.placeholder'))->setLabel($this->translator->translate('transaction.form.purchInvoiceNumber.label')); $this->add($purchInvoiceNumber); $purchInvoiceId = new Text('purchInvoiceId'); $purchInvoiceId->setAttribute('id', 'purchInvoiceId'); $this->add($purchInvoiceId); $paymentDate = new Date('paymentDate'); $paymentDate->setAttributes(array('id' => 'paymentDate', 'type' => 'text', 'class' => 'input datepicker form-control', 'data-date-weekstart' => 1, 'data-date-format' => 'dd.mm.yyyy')); $paymentDate->setAttribute('title', $this->translator->translate('web.form.document.docDate.title')); $paymentDate->setAttribute('readonly', 'readonly'); $paymentDate->setAttribute('placeholder', $this->translator->translate('web.form.document.docDate.placeholder')); $paymentDate->setLabel($this->translator->translate('web.form.document.docDate.label')); $this->add($paymentDate); $type = new Text('type'); $type->setAttribute('id', 'type'); $this->add($type); $name = new Text('name'); $name->setAttribute('id', 'name'); $name->setAttribute('class', 'form-control')->setAttribute('placeholder', $this->translator->translate('transaction.form.name.placeholder'))->setLabel($this->translator->translate('transaction.form.name.label')); $this->add($name); $referenceNumber = new Text('referenceNumber'); $referenceNumber->setAttribute('id', 'referenceNumber'); $referenceNumber->setAttribute('class', 'form-control')->setAttribute('placeholder', $this->translator->translate('transaction.form.referenceNumber.placeholder'))->setLabel($this->translator->translate('transaction.form.referenceNumber.label')); $this->add($referenceNumber); $sum = new Text('sum'); $sum->setAttribute('id', 'sum'); $sum->setAttribute('title', $this->translator->translate('transaction.form.amount.label')); $sum->setAttribute('class', 'form-control'); $sum->setAttribute('required', 'required'); $sum->setAttribute('placeholder', $this->translator->translate('transaction.form.amount.label')); $sum->setLabel($this->translator->translate('transaction.form.amount.label')); $this->add($sum); $description = new Text('description'); $description->setAttribute('id', 'description'); $description->setAttribute('class', 'form-control')->setAttribute('placeholder', $this->translator->translate('transaction.form.description.placeholder'))->setLabel($this->translator->translate('transaction.form.description.label')); $this->add($description); $payerIban = new Text('payerIban'); $payerIban->setAttribute('id', 'payerIban'); $payerIban->setAttribute('class', 'form-control')->setAttribute('placeholder', $this->translator->translate('transaction.form.payerIban.placeholder'))->setLabel($this->translator->translate('transaction.form.payerIban.label')); $this->add($payerIban); $archiveSign = new Text('archiveSign'); $archiveSign->setAttribute('id', 'archiveSign'); $archiveSign->setAttribute('class', 'form-control')->setAttribute('placeholder', $this->translator->translate('transaction.form.archiveSign.placeholder'))->setLabel($this->translator->translate('transaction.form.archiveSign.label')); $this->add($archiveSign); return $this; }