简体   繁体   中英

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?

Have you tried this:

    $form->addText('category_priority', 'Prioritizovať do')
    ->setType('date')
    ->setDefaultValue((new \DateTime)->format('Y-m-d'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM