Skip to content

Commit

Permalink
Datetime input default value can be set
Browse files Browse the repository at this point in the history
  • Loading branch information
czubehead committed Jul 11, 2017
1 parent 9a0fc7c commit 276647f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Inputs/DateTimeInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Czubehead\BootstrapForms\Enums\DateTimeFormat;
use DateTime;
use Nette\InvalidArgumentException;
use Nette\NotSupportedException;


Expand Down Expand Up @@ -59,6 +60,25 @@ public function getValue()
return $value;
}

/**
* @param DateTime|null $value
* @return static
*/
public function setValue($value)
{
if ($value instanceof DateTime) {
parent::setValue($value->format($this->format));

return $this;
}
elseif ($value === NULL) {
parent::setValue(NULL);

return $this;
}
throw new InvalidArgumentException('Value must be either DateTime or NULL');
}

public function validate()
{
parent::validate();
Expand Down

0 comments on commit 276647f

Please sign in to comment.