Compare commits

..
5 Commits
Author SHA1 Message Date
Tom Shafer 04c596a699 Update composer.json 2018-03-23 17:39:21 -07:00
Tom Shafer 3b177c17aa Update composer.json 2018-03-23 17:38:57 -07:00
Tortue Torche 33984f5e87 [5.5] Fix form method of hidden input '_method' is preserved on next request (#505)
This fix was merged in the pull request https://github.com/LaravelCollective/html/pull/460
But the pull request https://github.com/LaravelCollective/html/pull/471 accidentally revert this fix
2018-03-22 07:00:50 -07:00
Anderson Friaça b79edc7acf [5.5] Validation in select field for boolean value of selected option (#490)
* [5.5] Validation in select field for boolean value of selected option

* Adjustment
2018-02-12 06:19:55 -08:00
Tom Shafer 215f20b8c2 Update composer.json 2018-02-08 08:25:51 -08:00
7 changed files with 30 additions and 54 deletions

No files matched your search

+1 -1
View File
@@ -1,8 +1,8 @@
language: php language: php
php: php:
- 7.0
- 7.1 - 7.1
- 7.2
sudo: false sudo: false
+9 -9
View File
@@ -18,16 +18,16 @@
} }
], ],
"require": { "require": {
"php": ">=7.1.3", "php": ">=7.0.0",
"illuminate/http": "5.6.*", "illuminate/http": "5.5.*",
"illuminate/routing": "5.6.*", "illuminate/routing": "5.5.*",
"illuminate/session": "5.6.*", "illuminate/session": "5.5.*",
"illuminate/support": "5.6.*", "illuminate/support": "5.5.*",
"illuminate/view": "5.6.*" "illuminate/view": "5.5.*"
}, },
"require-dev": { "require-dev": {
"illuminate/database": "5.6.*", "illuminate/database": "5.5.*",
"mockery/mockery": "~1.0", "mockery/mockery": "~0.9.4",
"phpunit/phpunit": "~5.4" "phpunit/phpunit": "~5.4"
}, },
"autoload": { "autoload": {
@@ -40,7 +40,7 @@
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "5.6-dev" "dev-master": "5.5-dev"
}, },
"laravel": { "laravel": {
"providers": [ "providers": [
+3 -3
View File
@@ -49,11 +49,11 @@ trait FormAccessible
unset($keys[0]); unset($keys[0]);
$key = implode('.', $keys); $key = implode('.', $keys);
if (method_exists($relatedModel, 'hasFormMutator') && $key !== '' && $relatedModel->hasFormMutator($key)) { if ($this->hasFormMutator($key)) {
return $relatedModel->getFormValue($key); return $relatedModel->getFormValue($key);
} }
return data_get($relatedModel, empty($key)? null: $key); return data_get($relatedModel, $key);
} }
// No form mutator, let the model resolve this // No form mutator, let the model resolve this
@@ -81,7 +81,7 @@ trait FormAccessible
* *
* @return bool * @return bool
*/ */
public function hasFormMutator($key) protected function hasFormMutator($key)
{ {
$methods = $this->getReflection()->getMethods(ReflectionMethod::IS_PUBLIC); $methods = $this->getReflection()->getMethods(ReflectionMethod::IS_PUBLIC);
+11 -14
View File
@@ -527,7 +527,7 @@ class FormBuilder
// the element. Then we'll create the final textarea elements HTML for us. // the element. Then we'll create the final textarea elements HTML for us.
$options = $this->html->attributes($options); $options = $this->html->attributes($options);
return $this->toHtmlString('<textarea' . $options . '>' . e($value, false). '</textarea>'); return $this->toHtmlString('<textarea' . $options . '>' . e($value). '</textarea>');
} }
/** /**
@@ -709,23 +709,20 @@ class FormBuilder
* @param string $selected * @param string $selected
* @param array $attributes * @param array $attributes
* @param array $optionsAttributes * @param array $optionsAttributes
* @param integer $level
* *
* @return \Illuminate\Support\HtmlString * @return \Illuminate\Support\HtmlString
*/ */
protected function optionGroup($list, $label, $selected, array $attributes = [], array $optionsAttributes = [], $level = 0) protected function optionGroup($list, $label, $selected, array $attributes = [], array $optionsAttributes = [])
{ {
$html = []; $html = [];
$space = str_repeat("&nbsp;", $level);
foreach ($list as $value => $display) { foreach ($list as $value => $display) {
$optionAttributes = $optionsAttributes[$value] ?? []; $optionAttributes = $optionsAttributes[$value] ?? [];
if (is_array($display)) {
$html[] = $this->optionGroup($display, $value, $selected, $attributes, $optionAttributes, $level+5); $html[] = $this->option($display, $value, $selected, $optionAttributes);
} else {
$html[] = $this->option($space.$display, $value, $selected, $optionAttributes);
}
} }
return $this->toHtmlString('<optgroup label="' . e($space.$label, false) . '"' . $this->html->attributes($attributes) . '>' . implode('', $html) . '</optgroup>');
return $this->toHtmlString('<optgroup label="' . e($label) . '"' . $this->html->attributes($attributes) . '>' . implode('', $html) . '</optgroup>');
} }
/** /**
@@ -746,7 +743,7 @@ class FormBuilder
$string = '<option' . $this->html->attributes($options) . '>'; $string = '<option' . $this->html->attributes($options) . '>';
if ($display !== null) { if ($display !== null) {
$string .= e($display, false) . '</option>'; $string .= e($display) . '</option>';
} }
return $this->toHtmlString($string); return $this->toHtmlString($string);
@@ -769,7 +766,7 @@ class FormBuilder
'value' => '', '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) . '</option>');
} }
/** /**
@@ -1186,7 +1183,7 @@ class FormBuilder
} }
$request = $this->request($name); $request = $this->request($name);
if (! is_null($request) && $name != '_method') { if (! is_null($request) && $name !== '_method') {
return $request; return $request;
} }
@@ -1270,7 +1267,7 @@ class FormBuilder
*/ */
public function oldInputIsEmpty() public function oldInputIsEmpty()
{ {
return (isset($this->session) && count((array) $this->session->getOldInput()) === 0); return (isset($this->session) && count($this->session->getOldInput()) === 0);
} }
/** /**
+2 -2
View File
@@ -387,7 +387,7 @@ class HtmlBuilder
if (is_array($value)) { if (is_array($value)) {
return $this->nestedListing($key, $type, $value); return $this->nestedListing($key, $type, $value);
} else { } else {
return '<li>' . e($value, false) . '</li>'; return '<li>' . e($value) . '</li>';
} }
} }
@@ -456,7 +456,7 @@ class HtmlBuilder
} }
if (! is_null($value)) { if (! is_null($value)) {
return $key . '="' . e($value, false) . '"'; return $key . '="' . e($value) . '"';
} }
} }
-21
View File
@@ -42,16 +42,10 @@ class FormAccessibleTest extends PHPUnit_Framework_TestCase
public function testItCanMutateValuesForForms() public function testItCanMutateValuesForForms()
{ {
$model = new ModelThatUsesForms($this->modelData); $model = new ModelThatUsesForms($this->modelData);
$user = new User(['name' => 'Anton']);
$model->setRelation('user', $user);
$this->formBuilder->setModel($model); $this->formBuilder->setModel($model);
$this->assertEquals($model->getFormValue('string'), 'ponmlkjihgfedcba'); $this->assertEquals($model->getFormValue('string'), 'ponmlkjihgfedcba');
$this->assertEquals($model->getFormValue('created_at'), $this->now->timestamp); $this->assertEquals($model->getFormValue('created_at'), $this->now->timestamp);
$this->assertEquals($user, $model->getFormValue('user'));
$this->assertEquals('Get name: Anton', $model->getFormValue('user')->name);
$this->assertEquals('Get name for form: Anton', $model->getFormValue('user.name'));
} }
public function testItCanMutateRelatedValuesForForms() public function testItCanMutateRelatedValuesForForms()
@@ -165,18 +159,3 @@ class ModelThatDoesntUseForms extends Model
return '1 second ago'; return '1 second ago';
} }
} }
class User extends Model
{
use FormAccessible;
public function formNameAttribute($value)
{
return 'Get name for form: ' . $value;
}
public function getNameAttribute($value)
{
return 'Get name: ' . $value;
}
}
+4 -4
View File
@@ -467,7 +467,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
$select = $this->formBuilder->select('avc', [1 => 'Yes', 0 => 'No'], true, ['placeholder' => 'Select']); $select = $this->formBuilder->select('avc', [1 => 'Yes', 0 => 'No'], true, ['placeholder' => 'Select']);
$this->assertEquals( $this->assertEquals(
'<select name="avc"><option value="" hidden="hidden">Select</option><option value="1" selected>Yes</option><option value="0" >No</option></select>', '<select name="avc"><option value="">Select</option><option value="1" selected>Yes</option><option value="0" >No</option></select>',
$select $select
); );
} }
@@ -516,7 +516,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
['placeholder' => 'Select One...'] ['placeholder' => 'Select One...']
); );
$this->assertEquals($select, $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( $select = $this->formBuilder->select(
'size', 'size',
@@ -525,7 +525,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
['placeholder' => 'Select One...'] ['placeholder' => 'Select One...']
); );
$this->assertEquals($select, $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( $select = $this->formBuilder->select(
'encoded_html', 'encoded_html',
@@ -534,7 +534,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
['placeholder' => 'Select the &nbsp;'] ['placeholder' => 'Select the &nbsp;']
); );
$this->assertEquals($select, $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>'
); );
} }