Created
September 3, 2010 16:51
-
-
Save janmarek/564169 to your computer and use it in GitHub Desktop.
Nette datepicker
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
<?php | |
class BaseForm extends Nette\Application\AppForm | |
{ | |
public function addDatePicker($name, $label = NULL, $cols = NULL, $maxLength = NULL) | |
{ | |
return $this[$name] = new Nette\Forms\DatePicker($label, $cols, $maxLength); | |
} | |
} |
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
$("input.datepicker").livequery(function () { | |
$(this).datepicker(); | |
}); |
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
<?php | |
namespace Nette\Forms; | |
use DateTime; | |
class DatePicker extends TextInput | |
{ | |
/** @var string */ | |
private $format = "j.n.Y"; | |
public function __construct($label = NULL, $cols = NULL, $maxLength = NULL) | |
{ | |
parent::__construct($label, $cols, $maxLength); | |
$this->setAttribute("class", "datepicker"); | |
} | |
public function setValue($value) | |
{ | |
if ($value instanceof DateTime) { | |
parent::setValue($value->format($this->format)); | |
} else { | |
parent::setValue($value); | |
} | |
} | |
public function getValue() | |
{ | |
$dateTime = DateTime::createFromFormat($this->format, parent::getValue()); | |
return $dateTime ?: null; | |
} | |
public function getFormat() | |
{ | |
return $this->format; | |
} | |
public function setFormat($format) | |
{ | |
$this->format = $format; | |
} | |
public static function validateFilled(IFormControl $control) | |
{ | |
return $control->getValue() instanceof DateTime; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment