Answer the question
In order to leave comments, you need to log in
Only the last value of setValueOptions is added?
only the last value of setValueOptions is added;
{
"type": "select",
"label": "Select",
"className": "form-control",
"name": "select-1511596175604",
"values": [
{
"label": "Option 1",
"value": "option-1",
"selected": true
},
{
"label": "Option 2",
"value": "option-2"
},
{
"label": "Option 3",
"value": "option-3"
}
]
}
switch ($element->type) {
case 'select':
$selectElement = new Select($element->name);
$selectElement->setAttribute('class', $element->className);
foreach ($element->values as $option) {
$options = array(
$option->label => $option->value
);
$selectElement->setValueOptions($options);
}
$form->add($selectElement);
break;
}
Answer the question
In order to leave comments, you need to log in
Because you overwrite it on every iteration of the loop
$options = array();
foreach ($element->values as $option) {
$options[$option->label] = $option->value;
}
$selectElement->setValueOptions($options);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question