We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10378
    • 375 Posts
    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
      Freelancer @bitego http://www.bitego.com
      ---
      GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
      More infos here: http://www.bitego.com/extras/goodnews/
      • 3749
      • 24,544 Posts
      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.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 10378
        • 375 Posts
        Quote from: BobRay at Dec 15, 2012, 01:43 PM
        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.

        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).
          Freelancer @bitego http://www.bitego.com
          ---
          GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
          More infos here: http://www.bitego.com/extras/goodnews/
          • 3749
          • 24,544 Posts
          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.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting