Update multi dimensional data in the form in drupal 8

Case: update certain form field value during validation.

$form[‘latlon’][‘value’] = 110001;
$form[‘latlon’][‘distance’][‘from’][‘#default_value’] = 100 and need to change it to 200 during validation.

$distance = 200;
$form_state->setValue('latlon',
[
'value' => 110001,
'distance' =>
[
'from' => $distance
]
]
);

Leave a comment