3

I have a matrix field on my front-end form. Everything is working properly, data is saved correctly etc.

I am testing & trying to break things and I noticed I wasn't repopulating those fields if validation failed.

Here is how I am attempting to repopulate the value(s) in my front-end form:

<input type="hidden" name="fields[myMatrixFieldHandle][new1][type]" value="blockType">
<input type="hidden" name="fields[myMatrixFieldHandle][new1][enabled]" value="1">

...
value="{{ entry.myMatrixFieldHandle.blockType.fieldHandle }}"
...

When I dump the above, I am getting the whole object back. I'm not sure how to get to the actual field's value.

1 Answer 1

2

Using the example above, here is how you can re-populate the given matrix field(s). The below is assuming only one matrix field is visible by default [0]. Depending on your use case, you may need to dynamically generate the index number.

...
{%- if entry is defined %} value="{{ entry.myMatrixFieldHandle[0].fieldHandle }}"{% endif -%}
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.