Skip to content

Commit

Permalink
TextBase: fixed setEmptyValue() and space at the end of the string [C…
Browse files Browse the repository at this point in the history
…loses #35]
  • Loading branch information
chemix authored and dg committed Nov 5, 2014
1 parent 29f1608 commit 6c9ae32
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Forms/Controls/TextBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public function getValue()
{
$value = $this->value;
if (!empty($this->control->maxlength)) {
$value = Nette\Utils\Strings::substring($value, 0, $this->control->maxlength);
$value = Strings::substring($value, 0, $this->control->maxlength);
}
foreach ($this->filters as $filter) {
$value = (string) call_user_func($filter, $value);
}
return $value === $this->translate($this->emptyValue) ? '' : $value;
return $value === Strings::trim($this->translate($this->emptyValue)) ? '' : $value;
}


Expand Down Expand Up @@ -117,7 +117,7 @@ public function getControl()
{
$el = parent::getControl();
if ($this->emptyValue !== '') {
$el->attrs['data-nette-empty-value'] = $this->translate($this->emptyValue);
$el->attrs['data-nette-empty-value'] = Strings::trim($this->translate($this->emptyValue));
}
if (isset($el->placeholder)) {
$el->placeholder = $this->translate($el->placeholder);
Expand Down
11 changes: 11 additions & 0 deletions tests/Forms/Controls.TextBase.loadData.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ test(function() { // empty value
});


test(function() { // empty value
$_POST = array('phone' => '+420 ');

$form = new Form;
$input = $form->addText('phone')
->setEmptyValue('+420 ');

Assert::same( '', $input->getValue() );
});


test(function() { // invalid UTF
$_POST = array('invalidutf' => "invalid\xAA\xAA\xAAutf");

Expand Down
4 changes: 2 additions & 2 deletions tests/Forms/Controls.TextInput.render.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ test(function() { // validation rule RANGE with setType
test(function() { // setEmptyValue
$form = new Form;
$input = $form->addText('text')
->setEmptyValue('empty');
->setEmptyValue('empty ');

Assert::same('<input type="text" name="text" id="frm-text" data-nette-empty-value="empty" value="empty">', (string) $input->getControl());
Assert::same('<input type="text" name="text" id="frm-text" data-nette-empty-value="empty" value="empty ">', (string) $input->getControl());
});


Expand Down

0 comments on commit 6c9ae32

Please sign in to comment.