Question about system events

I have a multiselect TV that I’m just using for temporary purposes, and need to alter the selected values after the page is fully loaded for editing. The values for which select options need to be pre-selected are dynamically fetched using php in a plugin that runs OnDocFormRender. Is there some way to inject some ExtJS javascript that will do this?

UPDATE: this is solved below, but more questions about how system events work follow.

Could you just modify the PHP in the plugin to do what you want?

If not, you should be able to add a regClientStartupScript(getChunk('MyJS')); call to the plugin though the JS locators for the drop-down may be a bit tricky.

OK, finally found the answer after performing many Internet searches to find the right method. Here’s the code I needed:

OnDocFormRender, I create the value I need and then do this:
$resource->setTVValue(‘TVname’,$string);

And then OnDocFormSave, I do this to prevent the value from getting saved in the database:
$resource->setTVValue(‘TVname’,’’);

I had some confusion as to what fires when. So, does “OnDocFormSave” mean the script will execute after data is saved, or before it gets saved? I expected that it would run after data is saved, but it seems it runs before the save, because no TV Value gets saved to the database when I delete that value in my script OnDocFormSave.

Is there any map anywhere that shows all the system events, and what fires in what order?

I’m not aware of any official map of the system events, but I think the order is documented in my book – in the appendix listing the system events, and possibly somewhere in one of the later chapters. I had to spelunk into the core code to get the order.

Ah! I didn’t think to look there. That’s a very handy section, and even lists the available variables! Super useful.

I still don’t get, though, why clearing the TV value “OnDocFormSave” prevents it from getting into the database. Your book says OnDocFormSave “fires after the resource and parent are saved to the database”. When I ran my script “OnBeforeDocFormSave”, it didn’t prevent the TV from going into the database as I expected. From your description (it fires after fields and TVs have been set), I can see why OnBefore won’t do what I want. But it kind of seems like “OnBeforeDocFormSave” is really more accurately “OnAfterDocFormRender” (which doesn’t exist). I would expect that something called “OnBeforeDocFormSave” would be triggered by someone clicking the Save button, as way to change something before data gets saved. Maybe “OnDocFormSave” is really more like “after the save command has been issued”, not “after data has been saved to the database”?

Maybe it saves the TVs before firing the OnBeforeDocFormSave event.

Have you messed with OnDocFormPrerender?

No, I haven’t used that for anything yet.