Jump to content
Robin S

Limit Repeater

Recommended Posts

Similar to Limit PageTable, this module allows you to apply limits and restrictions to Repeater fields. RepeaterMatrix is not supported.

LimitRepeater

A module for ProcessWire CMS/CMF. Allows limits and restrictions to be placed on selected Repeater fields.

For any Repeater field you can limit the number of items that may be added and also prevent the use of drag-sorting, toggling of published state, and the trashing of items.

An example of use: because only non-superuser roles are affected by the module you can fix a Repeater at an arbitrary number of items by setting the limit to 1 and checking "No trash". Then as superuser you can add as many Repeater items as needed but other roles may not change the number of items.

Usage

Install the LimitRepeater module.

The module configuration screen should be self-explanatory.

You can add rows as needed using the "Add another row" button.

Please note that limits and restrictions are applied with CSS/JS so should not be considered tamper-proof.

 

https://github.com/Toutouwai/LimitRepeater
http://modules.processwire.com/modules/limit-repeater/

 

Module config:

limit-repeater-config.png

 

The effect of row 1 in the config screenshot above:

limit-r-example.png

  • Like 12

Share this post


Link to post
Share on other sites
13 minutes ago, adrian said:

@Robin S you're a man of no limits these days!

I'm really enjoying module development in PW. The flexibility that comes from hooks is brilliant. A couple more modules due shortly. :)

15 minutes ago, adrian said:

Btw, what is that text from

An all-time classic.

  • Like 1

Share this post


Link to post
Share on other sites

Very useful! I use it in combination with opening hours. For this reason I have created a repeater with 7 repeats (one for each day). In this case it prevents the customer from deleting or draging a weekday from the repeater list.

Screenshot_6.jpg

  • Like 6

Share this post


Link to post
Share on other sites

Thanks @Juergen! But how did you do the columns? No matter what Column Width settings I use, I have 100% width fields in my repeater... Am I missing something?

Share this post


Link to post
Share on other sites

Thanks! What is the firts one with 100%? I simply have two 50%, or 30%-30% or whatever, but the result is two 100% wide "columns". Strange... But thanx anyway. I will try to figure it out somehow.

Share this post


Link to post
Share on other sites

Its only here for creating the label and will not be displayed as a field in the template (see field settings below). I only use it to enter the day of the week (fe Monday). As you can see in my previous post every repeater has the name of the day in the repeater label.

Field settings of the hidden field:

Screenshot_8.jpg

 

  • Like 1

Share this post


Link to post
Share on other sites

Okay, finally I figured out that I was fiddling with the wrong settings, so that is why it "did not work".

Thanks to @Juergen who was kind enough to take a look at it!

Edit: Black Friday, eh? :-[

Edited by szabesz
  • Like 2

Share this post


Link to post
Share on other sites

v0.0.3 released. You can now select multiple roles to be affected by the limit/restrictions, including the superuser role and "all roles".

  • Like 4

Share this post


Link to post
Share on other sites

@Robin S Thanks for this very useful module!

I've not yet dug into its internals, but before I do, I'd like to know if it would it be possible to control the "trashability" of a repeater entry based on a value within it?  (I have a hidden field in one of my repeaters and I'd like to prevent deletion of items if that field is non-blank.)

Is the module ajax calling to check for conditions or is everything pushed into client-side JS?

Share this post


Link to post
Share on other sites

Hi @netcarver,

Right now the module can't do that. It's on my to-do list to update this module so that it has a hookable method that would allow the sort of thing you're wanting to do, but not sure when I'll get around to that.

For now you could use a hook to hide/disable the trash icon, similar to what I described in this topic:

In /site/ready.php:

$wire->addHookAfter('InputfieldFieldset::render', function(HookEvent $event) {
    /* @var $fieldset InputfieldFieldset */
    $fieldset = $event->object;
    $attr = $fieldset->wrapAttr();
    // Fieldsets in a Repeater inputfield have a data-page attribute
    if(isset($attr['data-page'])) {
        // Get the Repeater item
        $p = $this->pages((int) $attr['data-page']);
        if($p->hidden_field != '') $fieldset->addClass('no-trash');
    }
});

In some custom admin CSS:

/* Hide and disable the trash icon while keeping its space in the layout */
.no-trash .InputfieldRepeaterTrash { visibility:hidden; pointer-events:none; }

You could use display:none instead if you're not worried about the icon alignment.

  • Like 3

Share this post


Link to post
Share on other sites
1 hour ago, PWaddict said:

If I create a process module with a repeater field, will I be able to limit it with your module?

As far as I know, it's not possible to use a repeater field in a Process module. A repeater is necessarily a combination of fieldtype and inputfield whereas a Process module can only contain inputfields.

  • Thanks 1

Share this post


Link to post
Share on other sites

@PWaddict, if I understand right you want to set a limit of zero items. I added support for this in v0.1.6.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...