Jump to content

[solved] frontend edit on repeater fields


DarsVaeda
 Share

Recommended Posts

Hi,

how do I enable frontend editing for repeater fields?

It partially works with 

foreach($page->repeater_field as $item) {
>?
<li><edit list_item><?= $item->list_item ?></edit></li>
<?php
}

But if I click a frontend item the text disappears. I'm not sure if this is a bug or because it does not know which text it should reference.
I tried with:

foreach($page->repeater_field as $item) {
>?
<li><edit list_item_repeater<?= $item->id ?>><?= $item->list_item ?></edit></li>
<?php
}

But that results in an exception.

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

could this be related to permissions?

We currently encounter problems with frontend editing of repeater fields, too: in our case it's simply not possible to frontend-edit repeater fields for users with a specific role, although these users are able to edit the respective repeater fields in the regular backend page editor. Superusers are able to frontend-edit repeater fields as expected.

@DarsVaeda this is an example of how we included frontend-editing which works (apart from the problem described above):

<?php 
/** @var RepeaterPageArray $attributes */
foreach ($attributes as $attribute): ?>
  <div class="attribute">
    <?php $image = $attribute->get('image'); ?>
    <div class="attribute__image" edit="<?php echo $attribute->id; ?>.image">
      <img src="<?php echo $image->url; ?>" alt="<?php echo $image->description; ?>">
    </div>
    <div class="attribute__body">
      <?php echo $attribute->edit('body'); ?>
    </div>
  </div>
<?php endforeach; ?>

 

Cheers, Alex

Link to comment
Share on other sites

On 23/01/2017 at 8:14 PM, DarsVaeda said:

I tried with:


foreach($page->repeater_field as $item) {
>?
<li><edit list_item_repeater<?= $item->id ?>><?= $item->list_item ?></edit></li>
<?php
}

 

This is the actual problem. It doesn't work with this implementation.
If I use this:

foreach($page->repeater_field as $item) {
>?
<li><?= $item->edit('list_item') ?></li>
<?php
}

Then frontend editing works.

Thanks @design-a-point!

Link to comment
Share on other sites

I had the same issues you both mentioned. When logged in with some other role then superuser and try to edit a page, either the text disappeared or I wasn't even able to edit the text, at all.

The problem comes up, if you want to use option B (explained here: https://processwire.com/api/modules/front-end-editing/ ) for front end editing. 
I chose it above the other options, because of its direct "inline access" (compared to the dialog box with option C and D). Because repeater fields are stored as child of the admin page in the backend, other user roles don't have access to them by default, which leads to the afore mentioned issues, I guess. 
My solution was to give those user roles access to the admin page template and its children.

It took me some time to discover it, so if other users have problems with this, as well, maybe it's worth mentioning it in the module docs somewhere?

Link to comment
Share on other sites

23 minutes ago, Christoph said:

It took me some time to discover it, so if other users have problems with this, as well, maybe it's worth mentioning it in the module docs somewhere?

Did you check the front-end editing documentation when investigating your problem? It specifically advises against using option B for Repeaters:

Quote

But not worthwhile for things like Files/Images, PageTables, Repeaters or any field that you iterate to output or access object properties from. For those you will want to use <edit> tags or edit attributes, per options C and D.

 

  • Like 1
Link to comment
Share on other sites

Yes, I read it. 

As I had no problems using option B with repeaters as a superuser, I just wanted to make it work for other user roles, too. Option C/D is just no real front end editing any more, at least regarding how my clients understand it. In my current client's context, the front end editing is just needed to correct typos and the likes.

But you are right, as there is a strong advice to not use option B in a repeater context, the docs don't need to provide a solution on how make it work :).

Link to comment
Share on other sites

1 hour ago, Christoph said:

Option C/D is just no real front end editing any more, at least regarding how my clients understand it.

It is only option D that forces the modal dialog editor. Option C allows inline editing - you just have to place edit tags around the individual fields in your repeater rather than around the whole repeater foreach(). For example:

<?php foreach($page->my_repeater as $item): ?>
    <h3><edit <?= $item->id ?>.title><?= $item->title ?></edit></h3>
<?php endforeach; ?>

You're right that there does seem to be some sort of permissions issue for non-superusers, but rather than change access for the admin template (which non-superusers shouldn't have access to) I suggest you give edit access to your repeater template (select the "Show system templates" option to see repeater templates).

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

On 08/02/2017 at 10:00 AM, Robin S said:

Did you check the front-end editing documentation when investigating your problem? It specifically advises against using option B for Repeaters:

 

Is that documentation up to date? It doesn't work for me with option C. I get a popup which is not usable. Would need to dig into what is wrong with the html/css.
But option B works for me without any problem (despite the need to set the permission on the system template as you suggested).

Link to comment
Share on other sites

@DarsVaeda Had the same issue with unusable popup on option C/D. My solution was to change the jQuery version to the one processwire is using.

@Robin S Thanks for your help! Will try your solution with option C later today. You're right, instead of changing the admin template, it is enough to allow access for the repeater_content template

Link to comment
Share on other sites

9 hours ago, DarsVaeda said:

But option B works for me without any problem

5 hours ago, Christoph said:

where's the difference to option B in this case?

Re-reading the docs, I'm not sure why Ryan advises against using option B with Repeaters or PageTables (for Files/Images fields it makes sense). Maybe he means if you are wanting to make the entire Repeater/PageTable field editable rather than the individual fields inside the items, because it does seem to work fine for the latter case (once the access bug is worked around).

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...