how can i set default value in sonata admin bundle the data option is missing in configureFormFields method
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name', null, array('required' => true, 'data' => "my default value"))
;
}
how can use data attribute to set default value inside field ???
I presume you've probably already solved this by now, but as a reference to anyone else you can override the getNewInstance() method and set the default value on the object:
public function getNewInstance()
{
$instance = parent::getNewInstance();
$instance->setName('my default value');
return $instance;
}
you can also assign the default value to the property of the entity directly:
class TheEntity
{
private $name = 'default name';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With