I've come up with another solution to this problem: use a plugin that creates a resource for a newly entered location (in a seperated tv) and after it's created, checks it in the list. It's almost working as it should, at least for adding a resource the first time. The page reloads and the resource is added to the list and checked. But if I then add another new location and save the resource again, the page doesn't reload and the new location is not added to the list. So maybe I need a way to force reload of the page after each save. Anyone know how to do this?
This is the plugin so far (onDocFormSave):
To explain this a little more: when a user creates a new event, he can either (or both) check one or more existing locations in the checklist, or he can fill in details of a new location (name and telephone number). When he saves the event, the page reloads and the newly added location is already checked in the list. The fields for adding a new location are cleared.
$tel = $resource->getTVValue('locationTelephone');
$name = $resource->getTVValue('locationName');
// if details for new location have been filled, create this location
if ($name != '') {
$new = $modx->newObject('modResource');
$new->set('pagetitle', $name);
$new->set('published', '1');
$new->set('template', '2');
$new->set('parent', '1');
$new->save();
$new->setTVValue('locationTelephone', $tel);
$new->save();
// get id of new location
$newId = $new->get('id');
// list of checked locations on event resource
$checkedLocations = $resource->getTVValue('locationsList');
//add id of newly created resource to this list
$locationsNew = $checkedLocations.'||'.$newId;
// change value of checklist tv to add new id
$resource->setTVValue('locationsList', $locationsNew);
// clear input fields for new location
$resource->setTVValue('locationTelephone', '');
$resource->setTVValue('locationName', '');
}
Problem: when the user has added the first location, the page has reloaded and he fills in another location and saves again, this script isn't working anymore because the page doesn't reload, thus the new location is created and not added to the checklist. Also the fields for name and telephone number are not cleared. So: how do I refresh? Or should I use a different system event or something?