chrizz Posted November 4, 2013 Share Posted November 4, 2013 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 More sharing options...
ryan Posted November 8, 2013 Share Posted November 8, 2013 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. 4 Link to comment Share on other sites More sharing options...
owzim Posted May 28, 2014 Share Posted May 28, 2014 For me it's not clear yet. I stumbled upon that in Soma's module: InputfieldDimension.module Line 103 So $this corresponds to the Inputfield but when I look at CaptainHook there is no change hook for Inputfield, what am I not getting here? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now