Jump to content

Repeater field visibility in page selector


tinacious
 Share

Recommended Posts

Hello! It's been a while since I've done ProcessWire development, but I'm back (and quite rusty with it, and PHP). Forgive me if these questions have already been answered!

I have a field called dependencies that I would like to list a list of other fields. So far, I've been able to accomplish this by using the Input Field Type = Checkboxes and the template of the repeater field.

Let's say I have the following hierarchy:

  • Article (page)
    • Section (page)
      • Field (repeater field)
        • title
        • dependencies (PageArray)

I have the following data:

  • Commercial (article)
    • Basic terms (section)
      • Parking included? (field in repeater field)
      • Parking spots (field in repeater field)
  • Residential (article)
    • Basic terms (section)
      • Parking included? (field in repeater field)
      • Parking spots (field in repeater field)

I am using the page selector to represent a list of dependency fields. Currently, by using Checkboxes, I see all repeater fields in the app. I would like to limit it to all fields within the same parent article. For example, if I have 2 lease documents, they both have a section "Basic terms" and I would like to list "Parking included" as a dependency of "Parking spots." The UI is confusing if I see "Parking included?" twice with the checkbox UI. ASM Select, Page List Select, and Page Auto-complete do not expose repeater fields so I can't use those.

So, the solution to my problem could be one of the 2 (or maybe you have a better idea):

  • The ability to expose repeater fields to ASM Select, Page List Select, and Page Auto-complete
  • The ability to make a custom selector to include all repeater fields within the same article (template = article)

Thank you in advance for your help! ?

Link to comment
Share on other sites

Hi @tinacious,

Welcome back to ProcessWire :-).

I have gone over your posts several times and I can't make any sense of what the issue is :-). Maybe it's just me but I am wondering whether others too are failing to grasp the issue, hence the lack of responses? 

I can't tell whether you are talking about the backend or both backend and frontend.

On 4/17/2020 at 11:38 PM, tinacious said:

I have a field called dependencies that I would like to list a list of other fields.

What type of field is this?

On 4/17/2020 at 11:38 PM, tinacious said:

the template of the repeater field.

What template is this?

On 4/17/2020 at 11:38 PM, tinacious said:
  • Parking included? (field in repeater field)
  • Parking spots (field in repeater field)

What sort of fields are these?

On 4/17/2020 at 11:38 PM, tinacious said:

I am using the page selector to represent a list of dependency fields

I don't get what the page selector is ?

On 4/17/2020 at 11:38 PM, tinacious said:

Currently, by using Checkboxes, I see all repeater fields in the app.

What Checkboxes are these? Is it a field somewhere?

Maybe a screenshot or a drawing of what you are trying to achieve could help.

Link to comment
Share on other sites

  • 3 weeks later...

Picture the following hierarchy:

  • Canada
    • British Columbia
      • Vancouver
    • Ontario
      • Toronto
    • Nova Scotia
      • Halifax
  • United States
    • California
      • Los Angeles
    • New York
      • New York City

I used the word "page selector" but should've said "page reference."

Consider that I am trying to make a page reference for a city, so it has the template type of city, but I want to restrict cities to cities within the same country.

For example, I have a field on the city template that is called "similar city" but I only want to choose cities within the same country. I don't want the user to choose a city in a different country so I need to take the 2 following criteria into account:

  1. The template (city.php)
  2. The final parent Canada, if I'm trying to choose a Canadian city, or United States if I'm trying to choose an American city.

So something like:

$currentCountry = currentCity.getCountry();
$allowedCities = currentCountry.getAllCities();

Those allowedCities would be the ones I'd want to include in the Page Reference field.

Essentially, I need to make a custom selector that has some knowledge about what the root parent (other than home) is and filter for cities within that parent.

image.png

Link to comment
Share on other sites

1 hour ago, tinacious said:

Essentially, I need to make a custom selector that has some knowledge about what the root parent (other than home) is and filter for cities within that parent.

Assuming the "city" Page Reference field is in the "country" or "state" template, the selector string for selectable pages would be:

template=city, has_parent=page.rootParent

"page" in this context means the page that is being edited.

Link to comment
Share on other sites

12 hours ago, Robin S said:

Assuming the "city" Page Reference field is in the "country" or "state" template, the selector string for selectable pages would be:



 

Hi @Robin S thanks for your help. I've dumbed down the example since my initial example was difficult to understand. I'd actually be adding the Page Reference to a field on a repeater field on the city template.

The city example may be a bit simple to illustrate what I'm trying to do. 

I am trying to build dependencies with a legal document which has content types Article, Section, and ConfigurableField.

  • Article (page)
    • Section (page, child of either Article or Section to support infinite nesting of Section types)
      • ConfigurableField (repeater)
        • This has properties that can be configurable, e.g.
          • Field Name = short text
          • Field type = enum
          • Dependencies (Page Reference)
            • This is the field I'd like to say "get me any other ConfigurableField provided that it's in the same Article"

In the first screenshot is the field type used for my dependencies field. It is of Input field type = Checkboxes

In the second screenshot is the selector and template configuration. Currently I'm selecting any other repeater_configurable_field but I need to scope it to those only under the same Article (article.php). Other than Home, Article is the root. 

Would your suggestion work in this case? 

 

Update: I have tried your suggestion where I reference the configurable field, e.g.

template=configurable_field, has_parent=page.rootParent

That doesn't work but I can link to a section:

template=section, has_parent=page.rootParent

My guess that this isn't working is because, even though repeaters have a page-related API, they aren't surfaced as pages consistently in the API. For example, they are only surfaced when using the Page Reference of Input type Checkbox, and are not for the ASM Selector or other page selector types. And it seems that there may not be support for querying for it amongst pages.

I know I can access the repeaters in code, so I'm wondering if next I need to try a custom PHP-based selector rather than using a selector string.

 

Update: I have also tried the PHP-based one and with the selector string suggested, though that selector string works for sections and in the UI, it doesn't work in ready.php with the same selector string:

// Doesn't work even though this selector string works in the UI
$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
  if($event->object->hasField == 'dependencies') {
    $event->return = $event->pages->find('template=section, has_parent=page.rootParent');
  }
});


// Doesn't work either but if the first one doesn't work, I wasn't expecting this one to work.
$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
  if($event->object->hasField == 'dependencies') {
    $event->return = $event->pages->find('template=repeater_configurable_field, has_parent=page.rootParent');
  }
});

 

image.thumb.png.dce103a4d3847847b9d0753ecd90ceff.png

277330189_Edit_Field__dependencies__localhost.thumb.png.c9f629aca3dc51861af4354c98e1fdfa.png

Link to comment
Share on other sites

5 hours ago, tinacious said:

I have also tried the PHP-based one and with the selector string suggested, though that selector string works for sections and in the UI, it doesn't work in ready.php with the same selector string

When using the selector string option to define selectable pages, "page" is a special keyword that is dynamically replaced with the edited page. This only applies to the selector string option - if you are using the custom PHP code option you need to get the edited page in a different way. See the note at the bottom of your screenshot.

If you want to get Repeater pages in a selector by template you'll need to include "check_access=0" because the pages themselves are not directly accessible to non-superusers. But I actually think it's better in your case to get the Repeater pages the "normal" way, which is via the Repeater fields they belong to. So you would use the custom PHP code option to define the selectable pages, and the code would be something like this:

$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
	if($event->object->hasField == 'dependencies') {
		// Get the page being edited
		$page = $event->arguments('page');
		// Create a new PageArray to hold the selectable pages
		$selectable = new PageArray();
		// Get all the visible section pages under $page where configurable_field is not empty
		$sections = $page->find("template=section, configurable_field.count>0");
		foreach($sections as $section) {
			// Add the Repeater pages for each section to $selectable
			$selectable->add($section->configurable_field);
		}
		// Return the PageArray
		$event->return = $selectable;
	}
});

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...