Skip to content

Commit

Permalink
Merge pull request #12 from Lansoweb/develop
Browse files Browse the repository at this point in the history
Adding zend dateselect support
  • Loading branch information
Lansoweb committed Oct 24, 2015
2 parents 35cea78 + c929599 commit 7d668ce
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ The ideia is to facilitate the front development. You do not need to worry about

## ChangeLog

* 1.0.25
1. Added \Zend\Form\Element\DateSelect support

* 1.0.24
1. Added setBasePath to specify an url for the files (see each section bellow)

Expand Down
25 changes: 23 additions & 2 deletions src/LosUi/Form/View/Helper/FormRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Zend\Form\Element\Button;
use Zend\Form\Element\MonthSelect;
use Zend\Form\LabelAwareInterface;
use Zend\Form\Element\DateSelect;

/**
* Form row styled for Bootstrap 3.
Expand Down Expand Up @@ -112,7 +113,25 @@ public function render(ElementInterface $element, $isHorizontal = false, $labelC

$type = $element->getAttribute('type');

if ($type != 'checkbox' && $type != 'submit' && $type != 'button' && $type != 'radio' && $type != 'file' && $type != 'multi_checkbox') {
if ($element instanceof DateSelect) {
$attrs = $element->getDayAttributes();
$classAttributes = (in_array('class', $attrs) ? $attrs['class'].' ' : '');
$classAttributes = $classAttributes.'form-control';
$attrs['class'] = $classAttributes;
$element->setDayAttributes($attrs);

$attrs = $element->getMonthAttributes();
$classAttributes = (in_array('class', $attrs) ? $attrs['class'].' ' : '');
$classAttributes = $classAttributes.'form-control';
$attrs['class'] = $classAttributes;
$element->setMonthAttributes($attrs);

$attrs = $element->getYearAttributes();
$classAttributes = (in_array('class', $attrs) ? $attrs['class'].' ' : '');
$classAttributes = $classAttributes.'form-control';
$attrs['class'] = $classAttributes;
$element->setYearAttributes($attrs);
} elseif ($type != 'checkbox' && $type != 'submit' && $type != 'button' && $type != 'radio' && $type != 'file' && $type != 'multi_checkbox') {
$classAttributes = ($element->hasAttribute('class') ? $element->getAttribute('class').' ' : '');
$classAttributes = $classAttributes.'form-control';
$element->setAttribute('class', $classAttributes);
Expand Down Expand Up @@ -204,7 +223,7 @@ public function render(ElementInterface $element, $isHorizontal = false, $labelC

// Multicheckbox elements have to be handled differently as the HTML standard does not allow nested
// labels. The semantic way is to group them inside a fieldset
if (!$isHorizontal && ($type === 'multi_checkbox' || $type === 'radio' || $element instanceof MonthSelect)) {
if (!$isHorizontal && ($type === 'multi_checkbox' || $type === 'radio' || ($element instanceof MonthSelect && !$element instanceof DateSelect))) {
$markup = sprintf('<fieldset class="radio"><legend>%s</legend>%s</fieldset>', $label, $elementString);
} elseif ($type == 'checkbox') {
// Checkboxes need special treatment too
Expand Down Expand Up @@ -234,6 +253,8 @@ public function render(ElementInterface $element, $isHorizontal = false, $labelC
if ($element instanceof Button) {
$labelOpen = $labelClose = $label = '';
$addDivClass = ' col-xs-offset-'.$labelColumns;
} elseif ($element instanceof DateSelect) {
$elementString = '<div class="form-inline">'.$elementString.'</div>';
}
if ($type == 'radio') {
$addDivClass = ' radio';
Expand Down

0 comments on commit 7d668ce

Please sign in to comment.