Skip to content

Commit

Permalink
Added range, month, week. (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
djh101 authored and tshafer committed May 4, 2018
1 parent 4f3ba9f commit 327cff9
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,20 @@ public function password($name, $options = [])
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.
*
Expand Down Expand Up @@ -464,6 +478,10 @@ public function datetimeLocal($name, $value = null, $options = [])
*/
public function time($name, $value = null, $options = [])
{
if ($value instanceof DateTime) {
$value = $value->format('H:i');
}

return $this->input('time', $name, $value, $options);
}

Expand All @@ -481,6 +499,24 @@ public function url($name, $value = null, $options = [])
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.
*
Expand Down Expand Up @@ -968,6 +1004,24 @@ public function image($url, $name = null, $attributes = [])
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.
*
Expand Down
46 changes: 46 additions & 0 deletions tests/FormBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ public function testFormPassword()
$this->assertEquals('<input class="span2" name="foo" type="password" value="">', $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('<input name="foo" type="range">', $form1);
$this->assertEquals('<input name="foo" type="range" value="1">', $form2);
$this->assertEquals('<input class="span2" name="foo" type="range">', $form3);
}

public function testFormHidden()
{
$form1 = $this->formBuilder->hidden('foo');
Expand All @@ -240,6 +251,18 @@ public function testFormHidden()
$this->assertEquals('<input class="span2" name="foo" type="hidden">', $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('<input name="foo" type="month">', $form1);
$this->assertEquals('<input name="foo" type="month" value="' . \Carbon\Carbon::now()->format('Y-m') . '">',
$form2);
$this->assertEquals('<input class="span2" name="foo" type="month">', $form3);
}

public function testFormSearch()
{
$form1 = $this->formBuilder->search('foo');
Expand Down Expand Up @@ -310,6 +333,29 @@ public function testFormTime()
$this->assertEquals('<input class="span2" name="foo" type="time">', $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('<input name="foo" type="url">', $form1);
$this->assertEquals('<input name="foo" type="url" value="http://foobar.com">', $form2);
$this->assertEquals('<input class="span2" name="foo" type="url">', $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('<input name="foo" type="week">', $form1);
$this->assertEquals('<input name="foo" type="week" value="' . \Carbon\Carbon::now()->format('Y-\WW') . '">',
$form2);
$this->assertEquals('<input class="span2" name="foo" type="week">', $form3);
}

public function testFormFile()
{
$form1 = $this->formBuilder->file('foo');
Expand Down

0 comments on commit 327cff9

Please sign in to comment.