Skip to content

Commit 327cff9

Browse files
djh101tshafer
authored andcommitted
Added range, month, week. (#519)
1 parent 4f3ba9f commit 327cff9

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

src/FormBuilder.php

+54
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,20 @@ public function password($name, $options = [])
329329
return $this->input('password', $name, '', $options);
330330
}
331331

332+
/**
333+
* Create a range input field.
334+
*
335+
* @param string $name
336+
* @param string $value
337+
* @param array $options
338+
*
339+
* @return \Illuminate\Support\HtmlString
340+
*/
341+
public function range($name, $value = null, $options = [])
342+
{
343+
return $this->input('range', $name, $value, $options);
344+
}
345+
332346
/**
333347
* Create a hidden input field.
334348
*
@@ -464,6 +478,10 @@ public function datetimeLocal($name, $value = null, $options = [])
464478
*/
465479
public function time($name, $value = null, $options = [])
466480
{
481+
if ($value instanceof DateTime) {
482+
$value = $value->format('H:i');
483+
}
484+
467485
return $this->input('time', $name, $value, $options);
468486
}
469487

@@ -481,6 +499,24 @@ public function url($name, $value = null, $options = [])
481499
return $this->input('url', $name, $value, $options);
482500
}
483501

502+
/**
503+
* Create a week input field.
504+
*
505+
* @param string $name
506+
* @param string $value
507+
* @param array $options
508+
*
509+
* @return \Illuminate\Support\HtmlString
510+
*/
511+
public function week($name, $value = null, $options = [])
512+
{
513+
if ($value instanceof DateTime) {
514+
$value = $value->format('Y-\WW');
515+
}
516+
517+
return $this->input('week', $name, $value, $options);
518+
}
519+
484520
/**
485521
* Create a file input field.
486522
*
@@ -968,6 +1004,24 @@ public function image($url, $name = null, $attributes = [])
9681004
return $this->input('image', $name, null, $attributes);
9691005
}
9701006

1007+
/**
1008+
* Create a month input field.
1009+
*
1010+
* @param string $name
1011+
* @param string $value
1012+
* @param array $options
1013+
*
1014+
* @return \Illuminate\Support\HtmlString
1015+
*/
1016+
public function month($name, $value = null, $options = [])
1017+
{
1018+
if ($value instanceof DateTime) {
1019+
$value = $value->format('Y-m');
1020+
}
1021+
1022+
return $this->input('month', $name, $value, $options);
1023+
}
1024+
9711025
/**
9721026
* Create a color input field.
9731027
*

tests/FormBuilderTest.php

+46
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,17 @@ public function testFormPassword()
229229
$this->assertEquals('<input class="span2" name="foo" type="password" value="">', $form2);
230230
}
231231

232+
public function testFormRange()
233+
{
234+
$form1 = $this->formBuilder->range('foo');
235+
$form2 = $this->formBuilder->range('foo', 1);
236+
$form3 = $this->formBuilder->range('foo', null, ['class' => 'span2']);
237+
238+
$this->assertEquals('<input name="foo" type="range">', $form1);
239+
$this->assertEquals('<input name="foo" type="range" value="1">', $form2);
240+
$this->assertEquals('<input class="span2" name="foo" type="range">', $form3);
241+
}
242+
232243
public function testFormHidden()
233244
{
234245
$form1 = $this->formBuilder->hidden('foo');
@@ -240,6 +251,18 @@ public function testFormHidden()
240251
$this->assertEquals('<input class="span2" name="foo" type="hidden">', $form3);
241252
}
242253

254+
public function testFormMonth()
255+
{
256+
$form1 = $this->formBuilder->month('foo');
257+
$form2 = $this->formBuilder->month('foo', \Carbon\Carbon::now());
258+
$form3 = $this->formBuilder->month('foo', null, ['class' => 'span2']);
259+
260+
$this->assertEquals('<input name="foo" type="month">', $form1);
261+
$this->assertEquals('<input name="foo" type="month" value="' . \Carbon\Carbon::now()->format('Y-m') . '">',
262+
$form2);
263+
$this->assertEquals('<input class="span2" name="foo" type="month">', $form3);
264+
}
265+
243266
public function testFormSearch()
244267
{
245268
$form1 = $this->formBuilder->search('foo');
@@ -310,6 +333,29 @@ public function testFormTime()
310333
$this->assertEquals('<input class="span2" name="foo" type="time">', $form3);
311334
}
312335

336+
public function testFormUrl()
337+
{
338+
$form1 = $this->formBuilder->url('foo');
339+
$form2 = $this->formBuilder->url('foo', 'http://foobar.com');
340+
$form3 = $this->formBuilder->url('foo', null, ['class' => 'span2']);
341+
342+
$this->assertEquals('<input name="foo" type="url">', $form1);
343+
$this->assertEquals('<input name="foo" type="url" value="http://foobar.com">', $form2);
344+
$this->assertEquals('<input class="span2" name="foo" type="url">', $form3);
345+
}
346+
347+
public function testFormWeek()
348+
{
349+
$form1 = $this->formBuilder->week('foo');
350+
$form2 = $this->formBuilder->week('foo', \Carbon\Carbon::now());
351+
$form3 = $this->formBuilder->week('foo', null, ['class' => 'span2']);
352+
353+
$this->assertEquals('<input name="foo" type="week">', $form1);
354+
$this->assertEquals('<input name="foo" type="week" value="' . \Carbon\Carbon::now()->format('Y-\WW') . '">',
355+
$form2);
356+
$this->assertEquals('<input class="span2" name="foo" type="week">', $form3);
357+
}
358+
313359
public function testFormFile()
314360
{
315361
$form1 = $this->formBuilder->file('foo');

0 commit comments

Comments
 (0)