I have added a field as per Magento standard structure, hidden field appeared but value is not showing.
$fieldset->addField('entity_type_id', 'hidden',
array(
'name' => 'entity_type_id',
'value' => 11
));
NOTE : I have tried 'value' instead of 'values' but not working
Can anyone suggest how can I set the field value in Magento 2 admin form.
2 Answers 2
$this->setForm($form);
custom field with field value
$data=array('entity_type_id'=>11);
$form->setValues($data);
NOTE : I got reference from this answer and it is working perfectly fine for me for hidden field as well for text field.
Try This :-
Reference :- vendor/magento/module-sales/Block/Adminhtml/Order/Status/NewStatus/Form.php
Line no. 40
$fieldset->addField('entity_type_id', 'hidden',
[
'name' => 'entity_type_id',
'value' => 11
]);
-
1Hi @RkRathod it's not working. Value is not displaying in inspect element.Aditya Shah– Aditya Shah2019年09月09日 11:54:45 +00:00Commented Sep 9, 2019 at 11:54
-
if I add value using inspect element, even tho it is not showing in text field :DAditya Shah– Aditya Shah2019年09月09日 11:55:50 +00:00Commented Sep 9, 2019 at 11:55
-
@AdityaShah have you got solution?Manisha Vasani– Manisha Vasani2021年09月13日 13:57:33 +00:00Commented Sep 13, 2021 at 13:57
-
magento.stackexchange.com/a/288169/63138Aditya Shah– Aditya Shah2021年09月16日 07:15:59 +00:00Commented Sep 16, 2021 at 7:15
Explore related questions
See similar questions with these tags.