简体   繁体   English

Nette Form - 在 FormFactory 中为文本(类型日期)设置默认值

[英]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:这是我的 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'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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