From 327cff9376450657730906aa1fa10a6afdf2df4c Mon Sep 17 00:00:00 2001 From: Drew <5396418+djh101@users.noreply.github.com> Date: Fri, 4 May 2018 09:08:46 -0700 Subject: [PATCH] Added range, month, week. (#519) --- src/FormBuilder.php | 54 +++++++++++++++++++++++++++++++++++++++ tests/FormBuilderTest.php | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index e4ce357..f9a5471 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -329,6 +329,20 @@ class FormBuilder return $this->input('password', $name, '', $options); } + /** + * Create a range input field. + * + * @param string $name + * @param string $value + * @param array $options + * + * @return \Illuminate\Support\HtmlString + */ + public function range($name, $value = null, $options = []) + { + return $this->input('range', $name, $value, $options); + } + /** * Create a hidden input field. * @@ -464,6 +478,10 @@ class FormBuilder */ public function time($name, $value = null, $options = []) { + if ($value instanceof DateTime) { + $value = $value->format('H:i'); + } + return $this->input('time', $name, $value, $options); } @@ -481,6 +499,24 @@ class FormBuilder return $this->input('url', $name, $value, $options); } + /** + * Create a week input field. + * + * @param string $name + * @param string $value + * @param array $options + * + * @return \Illuminate\Support\HtmlString + */ + public function week($name, $value = null, $options = []) + { + if ($value instanceof DateTime) { + $value = $value->format('Y-\WW'); + } + + return $this->input('week', $name, $value, $options); + } + /** * Create a file input field. * @@ -968,6 +1004,24 @@ class FormBuilder return $this->input('image', $name, null, $attributes); } + /** + * Create a month input field. + * + * @param string $name + * @param string $value + * @param array $options + * + * @return \Illuminate\Support\HtmlString + */ + public function month($name, $value = null, $options = []) + { + if ($value instanceof DateTime) { + $value = $value->format('Y-m'); + } + + return $this->input('month', $name, $value, $options); + } + /** * Create a color input field. * diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index 90f2165..01c0cfc 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -229,6 +229,17 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase $this->assertEquals('', $form2); } + public function testFormRange() + { + $form1 = $this->formBuilder->range('foo'); + $form2 = $this->formBuilder->range('foo', 1); + $form3 = $this->formBuilder->range('foo', null, ['class' => 'span2']); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + $this->assertEquals('', $form3); + } + public function testFormHidden() { $form1 = $this->formBuilder->hidden('foo'); @@ -240,6 +251,18 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase $this->assertEquals('', $form3); } + public function testFormMonth() + { + $form1 = $this->formBuilder->month('foo'); + $form2 = $this->formBuilder->month('foo', \Carbon\Carbon::now()); + $form3 = $this->formBuilder->month('foo', null, ['class' => 'span2']); + + $this->assertEquals('', $form1); + $this->assertEquals('', + $form2); + $this->assertEquals('', $form3); + } + public function testFormSearch() { $form1 = $this->formBuilder->search('foo'); @@ -310,6 +333,29 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase $this->assertEquals('', $form3); } + public function testFormUrl() + { + $form1 = $this->formBuilder->url('foo'); + $form2 = $this->formBuilder->url('foo', 'http://foobar.com'); + $form3 = $this->formBuilder->url('foo', null, ['class' => 'span2']); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + $this->assertEquals('', $form3); + } + + public function testFormWeek() + { + $form1 = $this->formBuilder->week('foo'); + $form2 = $this->formBuilder->week('foo', \Carbon\Carbon::now()); + $form3 = $this->formBuilder->week('foo', null, ['class' => 'span2']); + + $this->assertEquals('', $form1); + $this->assertEquals('', + $form2); + $this->assertEquals('', $form3); + } + public function testFormFile() { $form1 = $this->formBuilder->file('foo');