[Forms] setDefault() method not reflected in HTML value attribute #16757
-
When setting a default value using public function initialize($entity = null, array $options = []): void
{
$elm = new Element\Hidden('id');
$elm->setFilters(['absint'])
->addValidator(
new Validator\PresenceOf(['message'=>'不正なアクセスです'])
)
->setDefault(0);
$this->add($elm);` In the controller I've written it like this. $newTicket = new Orders(['tickets_id'=>$tid]);
$form = new OrderForm($newTicket); And then in volt, I write it like this: {{ form.render('id') }} The resulting HTML was this: <input type="hidden" id="id" name="id" /> If I change the code in volt to <input type="hidden" id="id" name="id" value="1" /> This means that if you specify value as an attribute to render() when rendering, it will be reflected. So why isn't the value set with PHP 8.4.5 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Your issue is that you are passing an entity and that overrides the default form values. You see, if you do not pass any data to the form, it should render the Try to set your |
Beta Was this translation helpful? Give feedback.
Your issue is that you are passing an entity and that overrides the default form values. You see, if you do not pass any data to the form, it should render the
setDefault()
value.Try to set your
id
in your entity and that should work.