edster - 10 months ago

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.

Answer

ryanthompson - 10 months ago

Use the default_value config (pre-build)

ryanthompson - 10 months ago

Use the default_value config (pre-build)

edster - 10 months 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 - 10 months 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 - 10 months ago

Thanks!