'Nette Form - set default value on text (type date) in FormFactory
I have no idea how to set, or if it is even possible to set default value on text (type date).
Here is my FormFactory:
$form->addText('category_priority', 'Prioritizovať do')
->setHtmlType('date')
->setDefaultValue( $date ) // select from db in format Y-m-d ('2020-12-01')
->setHtmlAttribute('class', 'add');
I tried changing formats, because meaby it wont take the original one with this, but no luck:
use Nette\Utils\DateTime;
$original = DateTime::from($priority);
$priority = $original->format('d. m. Y');
Did somebody encountered same problem?
Solution 1:[1]
Have you tried this:
$form->addText('category_priority', 'Prioritizova? do')
->setType('date')
->setDefaultValue((new \DateTime)->format('Y-m-d'));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Eydun |
