Forum

Thread tagged as: Problem, Error

Perch repeater acting strangely with the editor on textarea

Please see following code:

<perch:repeater id="price_block" label="Price blocks">

<div class="block">


<div class="title">

<perch:content id="block_title" type="textarea" label="Title" textile="true" editor="markitup" />

</div>


<div class="price">

<strong>RRP</strong> &pound;<perch:content id="block_price" type="text" label="Price" />

</div>


<div class="clearall"></div>
</div>

</perch:repeater>

I am able to add the first Price block okay and can make parts of the Title bold, italic etc.

But when adding another when using repeater and trying to do the same, it refreshes the whole page and deletes all the content I've added.

Help!

Jack Linwood

Jack Linwood 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

it refreshes the whole page and deletes all the content I've added.

Could you clarify what that means?

If I was to start adding a new item and had filled in areas that came before this repeater and then tried what I mentioned the problem was, it would refresh the page and I would lose all the content I had filled in.

If I was editing an existing item then the content would still be there but it would still refresh the page.

Drew McLellan

Drew McLellan 2638 points
Perch Support

When you say new item, do you mean an item in a multiple item region, or a new item on the repeater?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Also, do you get any JavaScript errors in your browser console?

I mean a new item in a multiple item region.

So I have a template with a main title, description etc. at the start then half way through my template I have the repeater.

Would it help if I set you up as an editor to see the problem for yourself?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that would be helpful!

I can confirm what Jack is reporting, this happened to me too.

Fastest and simplest way to reproduce,
a simple region with just a repeater and a markitup textarea:

<perch:repeater id="miu_issue">
    <perch:content id="text" type="textarea" label="Texto" markdown="true" editor="markitup" size="xs" />
</perch:repeater>

After assigning the template, add two items and click any "button" of the markitup toolbar of the second repeater item and the page will reload. Happens in Firefox and Chrome.

Drew, did you receive my private ticket?

Little update, not just an issue with markitup but redactor too, although it doesn't reload the page, the button does nothing.

Seems to be an issue with how repeaters clone a field, using the textarea with the editors already initialized.

For markitup, the following works:

in core/assets/js/repeaters.js put the trigger call inside a promise

                renumber_repeater(repeater);
                verify_plusone_links();
            }).promise().done(function() {
                $(window).trigger('Perch.FieldTypes.redraw');
            });
        }
    }
    //$(window).trigger('Perch.FieldTypes.redraw');
});

then in markitup/config.js

$(document).ready(function(){
    var win = $(window);
    win.on('Perch_Init_Editors', function(){
    $('textarea.markitup.textile:not(:hidden):not(.markItUpEditor)').markItUp(textileSettings);
    $('textarea.markitup.markdown:not(:hidden):not(.markItUpEditor)').markItUp(markdownSettings);
    $('textarea.markitup.html:not(:hidden):not(.markItUpEditor)').markItUp(htmlSettings);
    });
    win.trigger('Perch_Init_Editors');

  win.on('Perch.FieldTypes.redraw', function() {
    win.trigger('Perch_Init_Editors');
  });
});

This way, the editor is attached after the textarea is cloned. For redactor, it should be a similar solution.

Hope it helps.

Hi Andrés,

Thanks for this although I can't seem to find markitup/config.js?

Also keen to hear from Drew whether there's a solution for this?

Drew McLellan

Drew McLellan 2638 points
Perch Support

This has changed in Perch 2.8, as it's a general class of problem with repeaters and blocks. 2.8 introduces an event callback for reinitialising editors when the UI changes.

Ah right, so just upload newest files and should fix the problem?

Drew McLellan

Drew McLellan 2638 points
Perch Support

When 2.8 is released, yes.

Oh sorry, I wasn't aware of the current version