Skip to content

Commit

Permalink
Merge pull request #5 from rolandoisidoro/fix-help-validation
Browse files Browse the repository at this point in the history
Fix "Help text" and "Validation" on form elements
  • Loading branch information
neilime authored Jul 10, 2018
2 parents eb2e7a9 + b4835e1 commit 09daff8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/TwbsHelper/Form/View/Helper/FormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function render(ElementInterface $oElement)
return sprintf(
static::$inputGroupFormat,
trim($sSpecialClass),
$sMarkup
$sMarkup . "%s"
);
}

Expand Down
12 changes: 11 additions & 1 deletion src/TwbsHelper/Form/View/Helper/FormElementErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@
*/
class FormElementErrors extends ZendFormElementErrorsViewHelper
{
/**@+
* @var string Templates for the open/close/separators for message tags
*/
protected $messageCloseString = '</div>';
protected $messageOpenFormat = '<div%s>';
protected $messageSeparatorString = '<br />';

/**
* @var array Default attributes for the open format tag
*/
protected $attributes = [
'class' => 'form-text'
'class' => 'invalid-feedback'
];
}
10 changes: 7 additions & 3 deletions src/TwbsHelper/Form/View/Helper/FormRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class FormRow extends ZendFormRowViewHelper
/**
* @var string
*/
protected static $helpBlockFormat = '<p class="help-block">%s</p>';
protected static $helpBlockFormat = '<small class="form-text text-muted">%s</small>';

/**
* The class that is added to element that have errors
* @var string
*/
protected $inputErrorClass = '';
protected $inputErrorClass = 'is-invalid';

/**
* @var string
Expand Down Expand Up @@ -332,9 +332,13 @@ protected function renderElement(ElementInterface $oElement, $sLabelPosition = n

// Render errors
if ($this->renderErrors) {
$sElementContent .= $this->getElementErrorsHelper()->render($oElement);
$sErrorMessages = $this->getElementErrorsHelper()->render($oElement);
} else {
$sErrorMessages = '';
}

$sElementContent = sprintf($sElementContent, $sErrorMessages);

return $sElementContent;

case Form::LAYOUT_HORIZONTAL:
Expand Down

0 comments on commit 09daff8

Please sign in to comment.