Hello,
creating a new resource -
is it possible to pre-fill a date TV field with a dynamically specified date?
We already experimented with the "Input Option Values" and the "Default Values" fields (we learned that this field doesn't accept bindings) of the TV by adding @EVAL bindings but without success.
I also tried to solve this problem by creating a plugin which reacts to the "OnDocFormPrerender" event - but the problem here is that I don't know how to reference to the TV as the resource id is "0" when creating a new resource.
Here is the plugin code:
switch($modx->event->name) {
case 'OnDocFormPrerender':
// check if fromDate has already been set
$fromDateTV = $resource->getTVValue('fromDate');
if ($fromDateTV != '') {
return;
}
$fromDateTV = $resource->setTVValue($newDate);
break;
}
return;
Thanks in advance,
Martin
Martin, here's some code that I use to set the value of the "Empty Cache" checkbox in a plugin connected to OnDocFormPrerender:
$modx->regClientStartupHTMLBlock('<script type="text/javascript">
Ext.onReady(function() {
Ext.getCmp("modx-resource-syncsite").setValue(false);
});
</script>');
You could use something similar if you use FireBug to find out what the ID of the TV is.
BTW, you don't need a switch statement if you're only connected to one event.
Quote from: BobRay at Dec 15, 2012, 01:43 PMMartin, here's some code that I use to set the value of the "Empty Cache" checkbox in a plugin connected to OnDocFormPrerender:
$modx->regClientStartupHTMLBlock('<script type="text/javascript">
Ext.onReady(function() {
Ext.getCmp("modx-resource-syncsite").setValue(false);
});
</script>');
You could use something similar if you use FireBug to find out what the ID of the TV is.
BTW, you don't need a switch statement if you're only connected to one event.
Hi Bob,
thanks for your hints!
The problem is, I need to set the TV value in database (not only in dom) as I need to reference to this value from a snippet which lists resources depending on the date in the TV.
In the meantime I know, it's simply not possible to do this before the resource is saved (which is logically as the database entry doesn't exist).
No, but I think you could do it in OnDocFormSave. The $resource should be available there so you could use $resource->setTVValue() as long as you know the name or Id of the TV.