<p>Turns our it was this line causing the issue:</p>

<pre><code>'collapsed' =&gt; true,
</code></pre>

<p>Removed it and all works as expected.</p>

CC BY-SA 4.0
2018-12-20T12:18:29.143Z
2018-12-20T12:18:29.143Z
ijust
<p>I have an entry with a matrix field which I'm updating from front-end. The update works fine, but when the (font-end) page reloads after submitting the form, the CP bundle assets get included (selectize.css, craft.css, charts.css). If I then reload the page, the CP assets are no longer included. I believe have narrowed it down to the use of $entry->setFieldValue(). Does anyone know why that's happening and how to stop it? Or is there a different way to update an entry with a matrix field from font-end that doesn't require me to use setFieldValue()?</p>

<p>Here's the relevant part of my update function:</p>

<pre><code>$field = Craft::$app-&gt;getFields()-&gt;getFieldByHandle('fieldHandle');
$existingMatrixQuery = $entry-&gt;getFieldValue('fieldHandle');

$serializedMatrix = $field-&gt;serializeValue($existingMatrixQuery, $entry);
$serializedMatrix['new1'] = [
    'type' =&gt; 'update',
    'enabled' =&gt; 1,
    'collapsed' =&gt; true,
    'fields' =&gt; array_merge($params['fields'], $params['required'])
];
$entry-&gt;setFieldValue('fieldHandle', $serializedMatrix);

if (Craft::$app-&gt;getElements()-&gt;saveElement($entry)) {
    return true;
}
</code></pre>

<craft3><matrix>
Updating matrix field from font-end with $entry->setFieldValue() pulls in Cp bundle on save
# Updating matrix field from font-end with $entry->setFieldValue() pulls in Cp bundle on save

(Asked by: username_0 on 2018-12-19)

I have an entry with a matrix field which I'm updating from front-end. The update works fine, but when the (font-end) page reloads after submitting the form, the CP bundle assets get included (selectize.css, craft.css, charts.css). If I then reload the page, the CP assets are no longer included. I believe have narrowed it down to the use of $entry->setFieldValue(). Does anyone know why that's happening and how to stop it? Or is there a different way to update an entry with a matrix field from font-end that doesn't require me to use setFieldValue()?
Here's the relevant part of my update function:
$field = Craft::$app->getFields()->getFieldByHandle('fieldHandle');
$existingMatrixQuery = $entry->getFieldValue('fieldHandle');

$serializedMatrix = $field->serializeValue($existingMatrixQuery, $entry);
$serializedMatrix['new1'] = [
    'type' => 'update',
    'enabled' => 1,
    'collapsed' => true,
    'fields' => array_merge($params['fields'], $params['required'])
];
$entry->setFieldValue('fieldHandle', $serializedMatrix);

if (Craft::$app->getElements()->saveElement($entry)) {
    return true;
}

**Tags:** craft3, matrix

---

## 1 answers

### Answer by username_0 on 2018-12-20. Score: 2

Turns our it was this line causing the issue:
'collapsed' => true,

Removed it and all works as expected.


---

