Jump to content

questions about the usage of trackChanges


chrizz
 Share

Recommended Posts

hi everybody!

I am a little bit confused about the usage of the "trackChanges" method. 

I use Hanis Select (aka Dropdown) fieldtype and I want to set a default value for a page. But: how do I track changes, when using the API?

I have a form where I set trackChanges to true. Afterwards I edit a form field (Hani's select) and set "trackChange($fieldname)". When I save the page there is no change tracked and the field won't be saved... :(

So my question: Is there any tutorial which explains the usage of trackChanges?

thanks in advance!

Link to comment
Share on other sites

trackChange() is a method on every Wire derived object, which includes most of ProcessWire's objects. The question would be what you are calling trackChange() on and whether the change tracking state is on or off? Also, there are related methods, also accessible everywhere that trackChange() is:

// turns change tracking ON or OFF
$obj->setTrackChanges(true|false); 

// returns TRUE if change tracking is ON or FALSE if off
$bool = $obj->trackChanges(); 

// returns an array of changes that have occurred
$array = $obj->getChanges(); 

// tracks the change, only if change tracking in ON
$obj->trackChange('field_name'); 

// clears the list of tracked changes
$obj->resetTrackChanges(); 

// hook that is called anytime a change occurs: only useful if you want something to be notified of a change
$obj->changed(); 

My best guess is that you may need to call $page->trackChange('field_name'); rather than the form itself. That's because the form is managing most of that on it's own, and may be clearing/resetting the trackChange call you did. Also, a page's changes are cleared after a successful save(), if that matters. 

  • Like 4
Link to comment
Share on other sites

  • 6 months later...

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