Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b7c357e78 | ||
|
|
7ea28eea5e | ||
|
|
3ff2b89ea4 | ||
|
|
7c02a4f0fd | ||
|
|
3617dac0c4 | ||
|
|
de73798e3e | ||
|
|
59f124084c | ||
|
|
0f4473f9a0 | ||
|
|
af7663294a | ||
|
|
f6d0f1c5c4 | ||
|
|
ebe5123467 |
No files matched your search
+16
-3
@@ -4,6 +4,7 @@ use DateTime;
|
|||||||
use Illuminate\Routing\UrlGenerator;
|
use Illuminate\Routing\UrlGenerator;
|
||||||
use Illuminate\Session\Store as Session;
|
use Illuminate\Session\Store as Session;
|
||||||
use Illuminate\Support\Traits\Macroable;
|
use Illuminate\Support\Traits\Macroable;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
class FormBuilder {
|
class FormBuilder {
|
||||||
|
|
||||||
@@ -624,7 +625,7 @@ class FormBuilder {
|
|||||||
{
|
{
|
||||||
$selected = $this->getSelectedValue($value, $selected);
|
$selected = $this->getSelectedValue($value, $selected);
|
||||||
|
|
||||||
$options = ['value' => e($value), 'selected' => $selected];
|
$options = ['value' => $value, 'selected' => $selected];
|
||||||
|
|
||||||
return '<option' . $this->html->attributes($options) . '>' . e($display) . '</option>';
|
return '<option' . $this->html->attributes($options) . '>' . e($display) . '</option>';
|
||||||
}
|
}
|
||||||
@@ -642,6 +643,7 @@ class FormBuilder {
|
|||||||
$selected = $this->getSelectedValue(null, $selected);
|
$selected = $this->getSelectedValue(null, $selected);
|
||||||
|
|
||||||
$options = compact('selected');
|
$options = compact('selected');
|
||||||
|
$options['value'] = '';
|
||||||
|
|
||||||
return '<option' . $this->html->attributes($options) . '>' . e($display) . '</option>';
|
return '<option' . $this->html->attributes($options) . '>' . e($display) . '</option>';
|
||||||
}
|
}
|
||||||
@@ -756,9 +758,20 @@ class FormBuilder {
|
|||||||
|
|
||||||
if($this->missingOldAndModel($name)) return $checked;
|
if($this->missingOldAndModel($name)) return $checked;
|
||||||
|
|
||||||
$posted = $this->getValueAttribute($name);
|
$posted = $this->getValueAttribute($name, $checked);
|
||||||
|
|
||||||
return is_array($posted) ? in_array($value, $posted) : (bool) $posted;
|
if (is_array($posted))
|
||||||
|
{
|
||||||
|
return in_array($value, $posted);
|
||||||
|
}
|
||||||
|
else if ($posted instanceof Collection)
|
||||||
|
{
|
||||||
|
return $posted->contains('id', $value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (bool) $posted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+3
-3
@@ -96,7 +96,7 @@ class HtmlBuilder {
|
|||||||
|
|
||||||
return '<img src="'.$this->url->asset($url, $secure).'"'.$this->attributes($attributes).'>';
|
return '<img src="'.$this->url->asset($url, $secure).'"'.$this->attributes($attributes).'>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a link to a Favicon file.
|
* Generate a link to a Favicon file.
|
||||||
*
|
*
|
||||||
@@ -313,7 +313,7 @@ class HtmlBuilder {
|
|||||||
*
|
*
|
||||||
* @param mixed $key
|
* @param mixed $key
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string $value
|
* @param mixed $value
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function listingElement($key, $type, $value)
|
protected function listingElement($key, $type, $value)
|
||||||
@@ -333,7 +333,7 @@ class HtmlBuilder {
|
|||||||
*
|
*
|
||||||
* @param mixed $key
|
* @param mixed $key
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string $value
|
* @param mixed $value
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function nestedListing($key, $type, $value)
|
protected function nestedListing($key, $type, $value)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use Collective\Html\FormBuilder;
|
|||||||
use Collective\Html\HtmlBuilder;
|
use Collective\Html\HtmlBuilder;
|
||||||
use Illuminate\Routing\UrlGenerator;
|
use Illuminate\Routing\UrlGenerator;
|
||||||
use Illuminate\Routing\RouteCollection;
|
use Illuminate\Routing\RouteCollection;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
@@ -322,7 +323,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
null,
|
null,
|
||||||
['placeholder' => 'Select One...']
|
['placeholder' => 'Select One...']
|
||||||
);
|
);
|
||||||
$this->assertEquals($select, '<select name="size"><option selected="selected">Select One...</option><option value="L">Large</option><option value="S">Small</option></select>');
|
$this->assertEquals($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',
|
||||||
@@ -330,7 +331,7 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
'L',
|
'L',
|
||||||
['placeholder' => 'Select One...']
|
['placeholder' => 'Select One...']
|
||||||
);
|
);
|
||||||
$this->assertEquals($select, '<select name="size"><option>Select One...</option><option value="L" selected="selected">Large</option><option value="S">Small</option></select>');
|
$this->assertEquals($select, '<select name="size"><option value="">Select One...</option><option value="L" selected="selected">Large</option><option value="S">Small</option></select>');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFormSelectYear()
|
public function testFormSelectYear()
|
||||||
@@ -409,6 +410,30 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormCheckboxWithModelRelation()
|
||||||
|
{
|
||||||
|
$this->formBuilder->setSessionStore($session = m::mock('Illuminate\Session\Store'));
|
||||||
|
$session->shouldReceive('getOldInput')->withNoArgs()->andReturn(array());
|
||||||
|
$session->shouldReceive('getOldInput')->with('items')->andReturn(null);
|
||||||
|
|
||||||
|
$mockModel2 = new StdClass;
|
||||||
|
$mockModel2->id = 2;
|
||||||
|
$mockModel3 = new StdClass;
|
||||||
|
$mockModel3->id = 3;
|
||||||
|
$this->setModel(array('items' => new Collection(array($mockModel2, $mockModel3))));
|
||||||
|
|
||||||
|
$check1 = $this->formBuilder->checkbox('items[]', 1);
|
||||||
|
$check2 = $this->formBuilder->checkbox('items[]', 2);
|
||||||
|
$check3 = $this->formBuilder->checkbox('items[]', 3, false);
|
||||||
|
$check4 = $this->formBuilder->checkbox('items[]', 4, true);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="items[]" type="checkbox" value="1">', $check1);
|
||||||
|
$this->assertEquals('<input checked="checked" name="items[]" type="checkbox" value="2">', $check2);
|
||||||
|
$this->assertEquals('<input name="items[]" type="checkbox" value="3">', $check3);
|
||||||
|
$this->assertEquals('<input checked="checked" name="items[]" type="checkbox" value="4">', $check4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormCheckboxWithoutSession()
|
public function testFormCheckboxWithoutSession()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->checkbox('foo');
|
$form1 = $this->formBuilder->checkbox('foo');
|
||||||
|
|||||||
Reference in new issue
Block a user