Tip how to change add button value on pagetable fields

Recommended Posts

If you want to add your own button value at the add button of a pagetable field, you only have to put this little piece of code inside your ready.php file.

$wire->addHookBefore('InputfieldPageTable::render', function($event) {
   $table = $event->object;
   if(!in_array($table->name, array('datespagetable'))) return;
      $this->addHookBefore("InputfieldButton::render", null, function(HookEvent $event){
         $button = $event->object;
         if($button->name == 'button'){
          $button->attr('value', 'Test');

In this case I limit it to a certain pagetable field called "datespagetable". You have to change it to the name of your desired pagetable field.

If you want to change it for all pagetable fields (no restrictions) simply remove the following line from the code:

if(!in_array($table->name, array('datespagetable'))) return;

If you want to add it to more than 1 pagetable field, then write all the fieldnames into the array:

if(!in_array($table->name, array('datespagetable','pagetable1','pagetable2'))) return;

You can change the value of the button text to your needs in this line of code:

$button->attr('value', 'Test');

I simply called it "Test" in this case to show how it is working.

If you need it to be a translateable string simply use:

$button->attr('value', __('Test'));

And now this is the result:




This let you customize your pagetable field a little bit. Fe you can use "Add News" or "Add new events" or something else.

If you want to change another attribute than the value please take a look at the following page: https://github.com/processwire/processwire/blob/master/wire/modules/Inputfield/InputfieldButton.module

Best regards

  • Like 2

Share this post

Link to post
Share on other sites
6 minutes ago, Juergen said:

I know, this is the solution if you have only 1 template assigned.:)

Yeah - I got it :) and appreciate your tip!

Just thought others might like clarification on how it works with multiple templates.

Share this post

Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.