Form addField and setField missing- dynamic set Form FieldValue

hi,

i have created 2 Forms and want to set the field Value dynamic. but i can not find how i can set the value for the field. i have found only addField but not setField. Can someone give a small tip :slight_smile:

Thx
BR
Peter

a bit confused what you are looking to do. Form displays values from associated model, even if you do not set it explcitly:

$form->model['field'] = 'value';

if you want to set field value through javascript, then:

$button->on('click', function() use($form) { 
   return $form->getField('field')->jsInput()->val('123');
});

Something like that…

Hi romaninsh,

thank you very much for the help. But if I want to update several fields or several forms. Unfortunately, there is only one return :frowning:

BR
Peter

wrap “return” value into array and you can update multiple fields like that.

$button->on('click', function() use($form) { 
   return [
     $form->getField('field1')->jsInput()->val('123'),
     $form->getField('field2')->jsInput()->val('123'),
   ];
});