Set field default values before displaying a form builder
Created 6 years ago by edster

Trying to set a few fields default values dynamically. However I can't figure out where in the build process or how to set them.

Tried using $builder->getForm()->setValue(key, value) but it doesn't work.

ryanthompson  —  6 years ago Best Answer

Use the default_value config (pre-build)

edster  —  6 years ago

@ryanthompson are you refering to on the fields?

Doing something like this doesn't work

 $fields = $checkoutBuilder->getFields();
$fields['lot'] = [
                    'default_value'    => $this->unit['lot'],
                    'readOnly' => TRUE
                ];

but doing the below does?

 $fields = $checkoutBuilder->getFields();
$fields['lot'] = [
                    'value'    => $this->unit['lot'],
                    'readOnly' => TRUE
                ];
ryanthompson  —  6 years ago

It's a config value: https://pyrocms.com/documentation/text-field-type/2.2/introduction/configuration

But it is supported across the board by core functionality - so it doesn't technically "live" in the FTs.

https://github.com/anomalylabs/streams-platform/blob/1.3/src/Ui/Form/Component/Field/FieldPopulator.php#L81

edster  —  6 years ago

Thanks!