1

I have Notification entry with sendTo field and nViewed matrix:
- viewedBy = Users field, limit of 1
- viewedDateTime = Plain Text

User's don't see whole front end form, just a 'Mark as Read' link. The link uses js to populate viewedDateTime and submit form. My form:

<form id="update-{{ msg.id }}" method="post" accept-charset="UTF-8">
   {{ csrfInput() }}
   <input type="hidden" name="action" value="entries/save-entry" />
   <input type="hidden" name="redirect" value="{{ theredirect }}" />
   <input type="hidden" name="sectionId" value="{{ msg.section.id }}" />
   <input type="hidden" name="entryId" value="{{ msg.id }}" />
   <input type="hidden" name="fields[nViewed]" />
   <input type="hidden" name="fields[nViewed][new1][type]" value="viewed" />
   <input type="hidden" name="fields[nViewed][new1][enabled]" value="1" />
   <input type="hidden" name="fields[nViewed][new1][fields][viewedBy][]" value="{{ currentUser.id }}" />
   <input type="hidden" name="fields[nViewed][new1][fields][viewedDateTime]" value="" />
   <button type="submit" class="tx-11 btn bd-0">Mark as read</button>
</form>

When the first user from sentTo clicks the 'Mark as Read' link, they get added to the matrix. All good.

When the second user from sentTo (testing on a different browser) clicks the 'Mark as Read' link it overwrites the first users row instead of adding another row to matrix.

I've also tried using field name="fields[nViewed][new{{ currentUser.id }}]... to make them unique but still overwrites.

What am I missing?
Amanda

1 Answer 1

2

According to the craft cms docs

To show a “New Block” form, first come up with a temporary ID for the block, prefixed with new:. For example, new:1, new:2, etc.

so, you need to you use prefix new: with the colon is a must.

3
  • Still no. Even made sure I upgraded from 3.4.0 to 3.4.14. Tried both [new:{{ currentUser.id }}] and [new:1]. Can you please link to craft docs? I can't find that page. Commented Apr 9, 2020 at 14:16
  • 1
    This is the page of craft docs, docs.craftcms.com/v3/matrix-fields.html#templating
    – aodihis
    Commented Apr 10, 2020 at 8:23
  • Classic case of RTFM. Commented Apr 14, 2020 at 1:49

Your Answer

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

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