Jump to content

Hook to add value to field when page is added


Flashmaster82
 Share

Recommended Posts

$wire->addHookAfter('Pages::added(template=booking)', function(HookEvent $event) {
        
$page = $event->arguments(0);
        
$selectable_pages = $page->getInputfield('booking_group')->getSelectablePages($page);    
   
$current_group = $selectable_pages->find("template=booking_price, parent.booking_current_group=1"); 
    
$first = $current_group->eq(0);
$second = $current_group->eq(1);
    
if ($page->booking_numberofpeople->id == 1 ) {
$page->setAndSave('booking_group', $first);
} 
        
    else if ($page->booking_numberofpeople->id !== 1 ) {
	$page->setAndSave('booking_group', $second);
    } 
   
    });

I have this code in ready.php

It works when i change to (Pages::save) but when (Pages::added) it doesn´t work? It sets the value to $second regardless..  Any clues?

booking_group = page reference field

booking_numberofpeople = select option field

the options in booking_numberofpeople is

1=1

2=2

3=3

4=4

5=5

Also i have set the required value to 1.

The pages are created from the module (Simple Contact Form).

 

Please help!!

 

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