Programmatically set default value for multiple row table webform element
YAML that looks like this:
- account: ''
adjustment: '123'
principal: ''
interest: ''
fee: ''
- account: ''
adjustment: '456'
principal: ''
interest: ''
fee: ''
- account: ''
adjustment: '789'
principal: ''
interest: ''
fee: ''
- account: ''
adjustment: '012'
principal: ''
interest: ''
fee: ''
- account: ''
adjustment: '345'
principal: ''
interest: ''
fee: ''
Can be done with code that looks like this:
#default_value] => Array
(
[0] => Array
(
[account] =>
[adjustment] => 123
[principal] =>
[interest] =>
[fee] =>
)
[1] => Array
(
[account] =>
[adjustment] => 456
[principal] =>
[interest] =>
[fee] =>
)
[2] => Array
(
[account] =>
[adjustment] => 789
[principal] =>
[interest] =>
[fee] =>
)
[3] => Array
(
[account] =>
[adjustment] => 012
[principal] =>
[interest] =>
[fee] =>
)
[4] => Array
(
[account] =>
[adjustment] => 345
[principal] =>
[interest] =>
[fee] =>
)
)
Adding a class in code:
[#attributes] => Array ( [class] => Array ( [0] => bold )
)
$elements['account'] = [
'#type' => 'textfield',
'#title' => t('Depository account'),
'#readonly' => TRUE,
'#attributes' => ['class' => ['row-label', 'bold']],
];
$elements['adjustment'] = [
'#type' => 'textfield',
'#title' => t('Prior month adjustment'),
'#input_mask' => "'alias': 'currency'",
];