Compare commits

...
5 Commits
Author SHA1 Message Date
Adrian Crisan b3a10245c7 Fix the issue where defaults has a higher priority then the attributes (#509) 2018-04-09 07:09:32 -07:00
ilyadrv 623a150c91 Placeholder for select element not hidden anymore (#493) (#499)
* Placeholder for select element not hidden anymore (#493)

* Fix tests for placeholder select element without hidden attribue
2018-03-16 09:57:31 -07:00
Devin 5060a6641d Fixed bug with radio button not being checked (#501)
* Fixed bug with radio button not being checked

Fixes: https://github.com/LaravelCollective/html/issues/496

Loose comparison needs to be done because Laravel model casting may be in affect and therfore 1 == true and 0 == false.

* typo
2018-03-16 09:57:16 -07:00
Anderson Friaça 41cd9291a6 [5.6] Validation in select field for boolean value of selected option (#491) 2018-02-12 06:19:42 -08:00
Tortue Torche 818efc2e16 [5.6] Form method of hidden input '_method' is preserved on next request (#486)
* Form method of hidden input '_method' is preserved on next request

E.G. When you submitted data across a form with a 'PATCH' method and then in a second submit you use a form with a 'DELETE' method, the FormBuilder::getValueAttribute() method use the previous value of the hidden input '_method'.
So the value is replaced by 'PATCH' instead of the 'DELETE' value.

* Drop PHP 7.1 and add PHP 7.2 in Travis CI config

Because Laravel 5.6 require at least PHP 7.1.3

* Fix PHP 7.2 Warning with count()

Otherwise a PHP Warning is thrown:
count(): Parameter must be an array or an object that implements Countable

See http://php.net/manual/en/migration72.incompatible.php#migration72.incompatible.warn-on-non-countable-types

* Bump Mockery version to support PHP 7.2
2018-02-08 10:38:44 -08:00
5 changed files with 51 additions and 13 deletions

No files matched your search

+1
View File
@@ -2,6 +2,7 @@ language: php
php:
- 7.1
- 7.2
sudo: false
+1 -1
View File
@@ -27,7 +27,7 @@
},
"require-dev": {
"illuminate/database": "5.6.*",
"mockery/mockery": "~0.9.4",
"mockery/mockery": "~1.0",
"phpunit/phpunit": "~5.4"
},
"autoload": {
+24 -8
View File
@@ -190,7 +190,7 @@ class FormBuilder
{
$this->model = $model;
}
/**
* Get the current model instance on the form builder.
*
@@ -572,7 +572,7 @@ class FormBuilder
*
* @param string $name
* @param array $list
* @param string $selected
* @param string|bool $selected
* @param array $selectAttributes
* @param array $optionsAttributes
* @param array $optgroupsAttributes
@@ -769,7 +769,7 @@ class FormBuilder
'value' => '',
];
return $this->toHtmlString('<option' . $this->html->attributes($options) . ' hidden="hidden">' . e($display, false) . '</option>');
return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . e($display, false) . '</option>');
}
/**
@@ -787,7 +787,9 @@ class FormBuilder
} elseif ($selected instanceof Collection) {
return $selected->contains($value) ? 'selected' : null;
}
if (is_int($value) && is_bool($selected)) {
return (bool)$value === $selected;
}
return ((string) $value === (string) $selected) ? 'selected' : null;
}
@@ -869,7 +871,7 @@ class FormBuilder
return $this->getRadioCheckedState($name, $value, $checked);
default:
return $this->getValueAttribute($name) === $value;
return $this->compareValues($name, $value);
}
}
@@ -922,7 +924,21 @@ class FormBuilder
return $checked;
}
return $this->getValueAttribute($name) === $value;
return $this->compareValues($name, $value);
}
/**
* Determine if the provide value loosely compares to the value assigned to the field.
* Use loose comparison because Laravel model casting may be in affect and therefore
* 1 == true and 0 == false.
*
* @param string $name
* @param string $value
* @return bool
*/
protected function compareValues($name, $value)
{
return $this->getValueAttribute($name) == $value;
}
/**
@@ -1184,7 +1200,7 @@ class FormBuilder
}
$request = $this->request($name);
if (! is_null($request)) {
if (! is_null($request) && $name != '_method') {
return $request;
}
@@ -1268,7 +1284,7 @@ class FormBuilder
*/
public function oldInputIsEmpty()
{
return (isset($this->session) && count($this->session->getOldInput()) === 0);
return (isset($this->session) && count((array) $this->session->getOldInput()) === 0);
}
/**
+1 -1
View File
@@ -94,7 +94,7 @@ class HtmlBuilder
{
$defaults = ['media' => 'all', 'type' => 'text/css', 'rel' => 'stylesheet'];
$attributes = array_merge($attributes, $defaults);
$attributes = array_merge($defaults, $attributes);
$attributes['href'] = $this->url->asset($url, $secure);
+24 -3
View File
@@ -464,6 +464,12 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
'<select name="countries"><option value="1" selected="selected">L</option><option value="2">M</option></select>',
$result
);
$select = $this->formBuilder->select('avc', [1 => 'Yes', 0 => 'No'], true, ['placeholder' => 'Select']);
$this->assertEquals(
'<select name="avc"><option value="">Select</option><option value="1" selected>Yes</option><option value="0" >No</option></select>',
$select
);
}
public function testSelectCollection()
@@ -510,7 +516,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
['placeholder' => 'Select One...']
);
$this->assertEquals($select,
'<select name="size"><option selected="selected" value="" hidden="hidden">Select One...</option><option value="L">Large</option><option value="S">Small</option></select>');
'<select name="size"><option selected="selected" value="">Select One...</option><option value="L">Large</option><option value="S">Small</option></select>');
$select = $this->formBuilder->select(
'size',
@@ -519,7 +525,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
['placeholder' => 'Select One...']
);
$this->assertEquals($select,
'<select name="size"><option value="" hidden="hidden">Select One...</option><option value="L" selected="selected">Large</option><option value="S">Small</option></select>');
'<select name="size"><option value="">Select One...</option><option value="L" selected="selected">Large</option><option value="S">Small</option></select>');
$select = $this->formBuilder->select(
'encoded_html',
@@ -528,7 +534,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
['placeholder' => 'Select the &nbsp;']
);
$this->assertEquals($select,
'<select name="encoded_html"><option selected="selected" value="" hidden="hidden">Select the &nbsp;</option><option value="no_break_space">&nbsp;</option><option value="ampersand">&amp;</option><option value="lower_than">&lt;</option></select>'
'<select name="encoded_html"><option selected="selected" value="">Select the &nbsp;</option><option value="no_break_space">&nbsp;</option><option value="ampersand">&amp;</option><option value="lower_than">&lt;</option></select>'
);
}
@@ -652,6 +658,21 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
$this->assertEquals('<input class="span2" name="foo" type="radio" value="foobar">', $form4);
}
public function testFormRadioWithAttributeCastToBoolean()
{
$this->setModel(['itemA' => true, 'itemB' => false]);
$radio1 = $this->formBuilder->radio('itemA', 1);
$radio2 = $this->formBuilder->radio('itemA', 0);
$radio3 = $this->formBuilder->radio('itemB', 1);
$radio4 = $this->formBuilder->radio('itemB', 0);
$this->assertEquals('<input checked="checked" name="itemA" type="radio" value="1">', $radio1);
$this->assertEquals('<input name="itemA" type="radio" value="0">', $radio2);
$this->assertEquals('<input name="itemB" type="radio" value="1">', $radio3);
$this->assertEquals('<input checked="checked" name="itemB" type="radio" value="0">', $radio4);
}
public function testFormRadioRepopulation()
{
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Contracts\Session\Session'));