Closed ishetnogferre closed 1 year ago
hey, An array with the selected values would be fine.
Hmm I tried that with following code (we're inserting a new block in a Supertable field which has dynamic checkboxes):
$superTableData["new$index"] = [
'type' => $blockType->id,
'enabled' => true,
'fields' => [
'offerService' => $item->offerService1->ids(),
'offerMethod' => $item->offerMethod1->ids(),
'offerAudience' => $item->offerAudience1->ids(),
'offerFinances' => $item->offerFinances1->ids(),
]
];
Which results into the following and the first one is a Category field which gets selected, but the checkboxes not.
array:2 [
"new1" => array:3 [
"type" => 1
"enabled" => true
"fields" => array:4 [
"offerService" => array:1 [
0 => 218
]
"offerMethod" => array:2 [
0 => 476
1 => 475
]
"offerAudience" => array:1 [
0 => 460
]
"offerFinances" => []
]
]
"new2" => array:3 [
"type" => 1
"enabled" => true
"fields" => array:4 [
"offerService" => array:1 [
0 => 235
]
"offerMethod" => []
"offerAudience" => []
"offerFinances" => []
]
]
This is my working test code. Hope that helps.
$entry = \craft\elements\Entry::find()->id(350)->one();
$entry->setFieldValue('superTable', [
'sortOrder' => [
'new1',
'new2'
],
'blocks' => [
'new1' => [
'type' => "1",
'fields' => [
'entriesRelationship' => [
'319',
'314'
],
'normalCheckboxes' => [
'option2',
'option4',
],
'sdfDropdown' => 'option2',
'sdfCheckboxesStaticOptions' => [
'option1',
'option3',
],
'sdfCheckboxesDynamicOptions' => [
'362',
'364',
],
]
],
'new2' => [
'type' => "1",
'fields' => [
'entriesRelationship' => [
'319',
'314'
],
'normalCheckboxes' => [
'option2',
'option4',
],
'sdfDropdown' => 'option2',
'sdfCheckboxesStaticOptions' => [
'option1',
'option3',
],
'sdfCheckboxesDynamicOptions' => [
'362',
'364',
],
]
]
]
]);
$saved = \Craft::$app->getElements()->saveElement($entry);
echo $saved;
exit;
Aha thanks, that helped! Needed to convert the int values from the ids() call to strings 😅
We're using the dynamic checkboxes on an entry, but we push some data via a plugin and were wondering what we would need to push to the dynamic checkboxes field for it to be selected?
An array with the selected values? An array with all the options and a selected key set on true?
Thanks in advance!