Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
819a87d564 | ||
|
|
d5618c3b22 | ||
|
|
3cd9e81140 | ||
|
|
d6157b709b | ||
|
|
2d25e47fb6 | ||
|
|
6a4f601e8b | ||
|
|
45857bf2ee | ||
|
|
6e459dc808 | ||
|
|
f229d1e629 | ||
|
|
2c93fdf913 | ||
|
|
9be410c461 | ||
|
|
8451f29340 |
No files matched your search
@@ -33,14 +33,25 @@ Next, update Composer from the Terminal:
|
|||||||
|
|
||||||
composer update
|
composer update
|
||||||
|
|
||||||
Finally, add your new provider to the `providers` array of `config/app.php`:
|
Next, add your new provider to the `providers` array of `config/app.php`:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
'providers' => [
|
'providers' => [
|
||||||
// ...
|
// ...
|
||||||
'Collective\Html\HtmlServiceProvider',
|
'Collective\Html\HtmlServiceProvider',
|
||||||
// ...
|
// ...
|
||||||
];
|
],
|
||||||
|
```
|
||||||
|
|
||||||
|
Finally, add two class aliases to the `aliases` array of `config/app.php`:
|
||||||
|
|
||||||
|
```php
|
||||||
|
'aliases' => [
|
||||||
|
// ...
|
||||||
|
'Form' => 'Collective\Html\FormFacade',
|
||||||
|
'Html' => 'Collective\Html\HtmlFacade',
|
||||||
|
// ...
|
||||||
|
],
|
||||||
```
|
```
|
||||||
|
|
||||||
<a name="opening-a-form"></a>
|
<a name="opening-a-form"></a>
|
||||||
@@ -48,9 +59,9 @@ Finally, add your new provider to the `providers` array of `config/app.php`:
|
|||||||
|
|
||||||
#### Opening A Form
|
#### Opening A Form
|
||||||
|
|
||||||
{{ Form::open(array('url' => 'foo/bar')) }}
|
{!! Form::open(array('url' => 'foo/bar')) !!}
|
||||||
//
|
//
|
||||||
{{ Form::close() }}
|
{!! Form::close() !!}
|
||||||
|
|
||||||
By default, a `POST` method will be assumed; however, you are free to specify another method:
|
By default, a `POST` method will be assumed; however, you are free to specify another method:
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php namespace Collective\Html;
|
<?php namespace Collective\Html;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
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;
|
||||||
@@ -298,6 +299,37 @@ class FormBuilder {
|
|||||||
return $this->input('email', $name, $value, $options);
|
return $this->input('email', $name, $value, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a number input field.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $value
|
||||||
|
* @param array $options
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function number($name, $value = null, $options = array())
|
||||||
|
{
|
||||||
|
return $this->input('number', $name, $value, $options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a date input field.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $value
|
||||||
|
* @param array $options
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function date($name, $value = null, $options = array())
|
||||||
|
{
|
||||||
|
if ($value instanceof Carbon)
|
||||||
|
{
|
||||||
|
$value = $value->format('Y-m-d');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->input('date', $name, $value, $options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a url input field.
|
* Create a url input field.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -239,6 +239,29 @@ class HtmlBuilder {
|
|||||||
return $this->listing('ul', $list, $attributes);
|
return $this->listing('ul', $list, $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a description list of items.
|
||||||
|
*
|
||||||
|
* @param array $list
|
||||||
|
* @param array $attributes
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function dl(array $list, array $attributes = [])
|
||||||
|
{
|
||||||
|
$attributes = $this->attributes($attributes);
|
||||||
|
|
||||||
|
$html = "<dl{$attributes}>";
|
||||||
|
|
||||||
|
foreach ($list as $key => $value)
|
||||||
|
{
|
||||||
|
$html .= "<dt>$key</dt><dd>$value</dd>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$html .= '</dl>';
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a listing HTML element.
|
* Create a listing HTML element.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -171,6 +171,31 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testFormNumber()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->number('foo');
|
||||||
|
$form2 = $this->formBuilder->number('foo', 1);
|
||||||
|
$form3 = $this->formBuilder->number('foo', null, ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="number">', $form1);
|
||||||
|
$this->assertEquals('<input name="foo" type="number" value="1">', $form2);
|
||||||
|
$this->assertEquals('<input class="span2" name="foo" type="number">', $form3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFormDate()
|
||||||
|
{
|
||||||
|
$form1 = $this->formBuilder->date('foo');
|
||||||
|
$form2 = $this->formBuilder->date('foo', '2015-02-20');
|
||||||
|
$form3 = $this->formBuilder->date('foo', \Carbon\Carbon::now());
|
||||||
|
$form4 = $this->formBuilder->date('foo', null, ['class' => 'span2']);
|
||||||
|
|
||||||
|
$this->assertEquals('<input name="foo" type="date">', $form1);
|
||||||
|
$this->assertEquals('<input name="foo" type="date" value="2015-02-20">', $form2);
|
||||||
|
$this->assertEquals('<input name="foo" type="date" value="' . \Carbon\Carbon::now()->format('Y-m-d') . '">', $form3);
|
||||||
|
$this->assertEquals('<input class="span2" name="foo" type="date">', $form4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testFormFile()
|
public function testFormFile()
|
||||||
{
|
{
|
||||||
$form1 = $this->formBuilder->file('foo');
|
$form1 = $this->formBuilder->file('foo');
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Session\Store;
|
||||||
|
use Mockery as m;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Collective\Html\FormBuilder;
|
||||||
|
use Collective\Html\HtmlBuilder;
|
||||||
|
use Illuminate\Routing\UrlGenerator;
|
||||||
|
use Illuminate\Routing\RouteCollection;
|
||||||
|
|
||||||
|
class HtmlBuilderTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup the test environment.
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->urlGenerator = new UrlGenerator(new RouteCollection, Request::create('/foo', 'GET'));
|
||||||
|
$this->htmlBuilder = new HtmlBuilder($this->urlGenerator);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the test environment.
|
||||||
|
*/
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
m::close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDl()
|
||||||
|
{
|
||||||
|
$list = [
|
||||||
|
'foo' => 'bar',
|
||||||
|
'bing' => 'baz'
|
||||||
|
];
|
||||||
|
|
||||||
|
$attributes = ['class' => 'example'];
|
||||||
|
|
||||||
|
$result = $this->htmlBuilder->dl($list, $attributes);
|
||||||
|
|
||||||
|
$this->assertEquals('<dl class="example"><dt>foo</dt><dd>bar</dd><dt>bing</dt><dd>baz</dd></dl>', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in new issue
Block a user