Jump to content

Custom Repeater field input title?


adinuno
 Share

Recommended Posts

  • 3 months later...
  • 2 months later...
  • 5 months later...

The title function renderRepeaterLabel is hookable.  Here's a generic example, which applies to all Repeater fieldtypes:

class RepeaterTitle extends WireData implements Module {

	/**
	 * getModuleInfo is a module required by all modules to tell ProcessWire about them
	 *
	 * @return array
	 *
	 */
	public static function getModuleInfo() {

		return array(

			// The module'ss title, typically a little more descriptive than the class name
			'title' => 'Repeater Title', 

			// version number 
			'version' => 0.1, 

			// summary is brief description of what this module is
			'summary' => 'An example module used for demonstration purposes.',
			
			// Optional URL to more information about the module
			'href' => 'http://processwire.com',

			// singular=true: indicates that only one instance of the module is allowed.
			// This is usually what you want for modules that attach hooks. 
			'singular' => true, 

			// autoload=true: indicates the module should be started with ProcessWire.
			// This is necessary for any modules that attach runtime hooks, otherwise those
			// hooks won't get attached unless some other code calls the module on it's own.
			// Note that autoload modules are almost always also 'singular' (seen above).
			'autoload' => true

			);
	}

	/**
	 * Initialize the module
	 *
	 * ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called
	 * when ProcessWire's API is ready. As a result, this is a good place to attach hooks. 
	 *
	 */
	public function init() {
		$this->addHookBefore('InputfieldRepeater::renderRepeaterLabel', $this, 'repeaterLabel'); 

	}

	public function repeaterLabel($event) {
		// Replace function
		$event->replace = true;
		// Arguments: $label, $cnt, Page $page
		$page = $event->arguments(2);
		// Show repeater page body instead
		$event->return = $page->body;
	}

	
}

Not sure what the best way is to replace the title per specific instance of a Repeater field -- I'm still learning my way around hooks.  But I'm sure someone else knows!

  • Like 1
Link to comment
Share on other sites

  • 2 years later...

Does anyone know if this possible yet?

Ideally, I would like to select the text entry of a specific field within my repeater to appear as the label for each repeater section.

Any clues as to how to do this through the GUI greatly appreciated!

Link to comment
Share on other sites

32 minutes ago, kathep said:

Does anyone know if this possible yet?

Ideally, I would like to select the text entry of a specific field within my repeater to appear as the label for each repeater section.

Any clues as to how to do this through the GUI greatly appreciated!

Is this what you are looking for?

Screen Shot 2017-02-13 at 12.03.23 PM.png

Link to comment
Share on other sites

  • 2 weeks later...

Hi @adrian

No. I currently use that, and it is frustrating, leading me to ask my question. 

What I want is something that will change the label on the field to the text entry of a specific field within my repeater. So when I create a new repeater, and there is a field called 'Title' within the repeater, once I enter text into the title field (for examples sake, let's say I title my repeater 'Introductory Exercise' and click 'save' on the page, the title of the repeater field in the header bar would change to 'Introductory Exercise'. 

Link to comment
Share on other sites

@kathep - sorry, I think I must not be understanding properly. Would you mind posting some screenshots showing your repeater settings and an example screenshot of a completed "Introductory Exercise" title and what the repeater header bar looks like after saving?

Link to comment
Share on other sites

Hi @adrian

Thanks for your quick reply. As you see, my repeater is called lesson_plan_section and has a label title of 'section'. Ideally, I would like the label text box to be able to take and process some code that says 'get text entry from the field within the repeater called "subject" and add it here'.

58b078ab79462_Screenshot2017-02-2410_15_56.thumb.png.7dd75d1896954b3d3864e978c4527673.png

Here is my template 'class.php', where I have the repeater field 'lesson plan section'. As you see, each of the repeaters has a name of section #1, section #2 etc. I reguarly work with 20 sections, and the numbers are an unintuitive and awkward way to remember which section is which.

58b078b6d3049_Screenshot2017-02-2410_14_50.thumb.png.3e058412d627d7c9356ac3190b46a058.png
58b078b078595_Screenshot2017-02-2410_15_03.thumb.png.9f0ac02173991a108b69f381e7740e71.png

This is why I'm looking for a more user friendly solution. Unfortunately, my php skills are beginner, so I have no idea where to start in terms of hacking a solution for myself.
 

Link to comment
Share on other sites

There is no 'repeater item labels' section on my details tab. See below - these are the only two options I see above the 'save' button at the end of the screen:

58b07ca8d8ace_Screenshot2017-02-2410_33_32.thumb.png.b121a10f6a12bf88515b84f865c4bd28.png

I'm using Processwire version 2.6.5 dev. Could the setting you mention only appear in a more recent version of Processwire?

Link to comment
Share on other sites

3 minutes ago, kathep said:

I'm using Processwire version 2.6.5 dev. Could the setting you mention only appear in a more recent version of Processwire?

Yeah, that would be the problem. If you use repeaters a lot, then I would highly recommend updating to the latest dev version of ProcessWire. There were a lot of great new repeater features introduced in 3.0.44 (http://processwire.com/blog/posts/pw-3.0.44-repeaters/) - we are now at 3.0.52. I do think the automated header from title was available before this, but would need to track down exactly when.

2.6.5 is REALLY old now :)

  • Like 1
Link to comment
Share on other sites

Just now, adrian said:

2.6.5 is REALLY old now :)

Ah ok, mystery solved. Thanks for the help Adrian!

This shows how I have been neglecting my processwire install for some time. Looking forward to enjoying all the improvements after updating!

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...