This repository has been archived by the owner on Feb 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from AydinHassan/datetime-local-support
datetime-local support
- Loading branch information
Showing
6 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace AdamWathan\Form\Elements; | ||
|
||
class DateTimeLocal extends Text | ||
{ | ||
protected $attributes = [ | ||
'type' => 'datetime-local', | ||
]; | ||
|
||
public function value($value) | ||
{ | ||
if ($value instanceof \DateTime) { | ||
$value = $value->format('Y-m-d\TH:i'); | ||
} | ||
|
||
return parent::value($value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use AdamWathan\Form\Elements\DateTimeLocal; | ||
|
||
class DateTimeLocalTest extends PHPUnit_Framework_TestCase | ||
{ | ||
use InputContractTest; | ||
|
||
protected function newTestSubjectInstance($name) | ||
{ | ||
return new DateTimeLocal($name); | ||
} | ||
|
||
protected function getTestSubjectType() | ||
{ | ||
return 'datetime-local'; | ||
} | ||
|
||
public function testDateTimeValuesAreBoundAsFormattedStrings() | ||
{ | ||
$dateTimeLocal = new DateTimeLocal('dob'); | ||
$dateTimeLocal->value(new DateTime('12-04-1988 10:33')); | ||
|
||
$expected = '<input type="datetime-local" name="dob" value="1988-04-12T10:33">'; | ||
$this->assertSame($expected, $dateTimeLocal->render()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters