We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    Looking for options to validate a TV against another TV (is strat date before end date) before a user saves a resource. Are there extras or manager tools to do this or am I stuck writing a plugin?
      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
      • 44195
      • 293 Posts
      I think that would need to be a plugin. It should be quite straight forward though providing you've got the resource ids and TV names that you need.
        I'm lead developer at Digital Penguin Creative Studio in Hong Kong. https://www.digitalpenguin.hk
        Check out the MODX tutorial series on my blog at https://www.hkwebdeveloper.com
        • 3749
        • 24,544 Posts
        I think it might be simple as something like this, connected to OnBeforeDocFormSave:

        $start = strtotime($resource->getTVValue('start_date'));
        $end = strtotime($resource->getTVValue('end_date'));
        
        if ((!empty($start)) && (!empty($end)))
            if ($end < $start) {
                return (array('End date must be later than start date'));
            }
        }
        
        return;
        


        It should display the error message, but I've never tested it.

        This will check both new and existing resources on save. If you don't want that, you can put something like this at the top:

        if ($mode === modSystemEvent::MODE_NEW) {
            return '';
        }
        


        You may also want to add a test of $resource->get('parent') or $resource->get('id') at the top to limit it to specific resources.



          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
          • 26503
          • 620 Posts
          Quote from: BobRay at Feb 12, 2019, 07:08 PM
          I think it might be simple as something like this, connected to OnBeforeDocFormSave:

          $start = strtotime($resource->getTVValue('start_date'));
          $end = strtotime($resource->getTVValue('end_date'));
          
          if ((!empty($start)) && (!empty($end)))
              if ($end < $start) {
                  return (array('End date must be later than start date'));
              }
          }
          
          return;
          


          It should display the error message, but I've never tested it.

          This will check both new and existing resources on save. If you don't want that, you can put something like this at the top:

          if ($mode === modSystemEvent::MODE_NEW) {
              return '';
          }
          


          You may also want to add a test of $resource->get('parent') or $resource->get('id') at the top to limit it to specific resources.




          thanks Bob - ya - it looks good.
            *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

            Sean Kimball CLP, CLS.
            Technical Director / Sr. Developer | BigBlock Studios
            ._______________________________________________.
            Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
            27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
            phone/fax: 905-426-5525
            • 3749
            • 24,544 Posts
            Don't thank me until it works. wink
              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