We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    On the Create/Edit Resource panel, I have some PHP and JS that clears the date TV and saves the resource. Unfortunately, the date TV is not updated on the screen until I reload the page (which I'd rather not do).

    Both of these lines work without error, and the first one does change the stored value of the TV, but neither one clears the TV on the screen.

    document.getElementById('tv17').value = "";
    document.getElementById("tv17-tr").getElementsByTagName("td")[0].getElementsByTagName("input").value="";
    

    Does anyone know a way to clear the displayed value?
      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
      • 17301
      • 932 Posts
      Does this work?

      document.getElementById('tv17').removeAttribute('value');
        ■ email: [email protected] | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • 3749
        • 24,544 Posts
        It returns undefined in the console. I'll try it in real code later on. I doubt that it will work since the element with 'tv17' as an ID is hidden at all times.

        If you examine a date/time TV with Chrome Dev. tools or Firebug, you can see that it's kind of a rat's nest.

        [update] Sorry, no effect. [ed. note: BobRay last edited this post 6 years, 10 months ago.]
          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
          • 17301
          • 932 Posts
          I see.

          I'll document it here just so others can understand and maybe help.

          The value for a date/time TV is stored in a hidden input field as such (in my case tv24):

          <input id="tv24" class="datefield x-form-hidden x-form-field" value="2017-05-23 03:15:00" name="tv24" onblur="MODx.fireResourceFormChange();" type="hidden"> 


          The data/time TV fields that are rendered on page load and are generated by this code:

          Ext.onReady(function() {
              var fld = MODx.load({
              
                  xtype: 'xdatetime'
                  ,applyTo: 'tv24'
                  ,name: 'tv24'
                  ,dateFormat: MODx.config.manager_date_format
                  ,timeFormat: MODx.config.manager_time_format
                                                  
                                          
                  ,dateWidth: 198
                  ,timeWidth: 198
                  ,allowBlank: true        
                  ,value: '2017-05-23 02:15:00'
                  ,msgTarget: 'under'
              
                  ,listeners: { 'change': { fn:MODx.fireResourceFormChange, scope:this}}
              });
              Ext.getCmp('modx-panel-resource').getForm().add(fld);
          });


          Everytime you run the above code a new div that houses the rendered input fields is generated with a generated id:
          #ext-gen518


          Unfortunately the actual ID's of the input fields are also incrementally generated. ie:

          <input id="ext-comp-1185-date"
          <input id="ext-comp-1186-date"


            ■ email: [email protected] | ■ website: https://alienbuild.uk

            The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
            • 3749
            • 24,544 Posts
            I'm thought I hated modExt before, but I've reached a whole new level. wink

            I posted a solution earlier, but for some reason I don't see it here.

            document.getElementById('tv17').value = '';
            document.getElementById("tv17-tr").getElementsByTagName("td")[0].getElementsByTagName("input")[0].value="";
            MODx.fireResourceFormChange();
            

            I was missing the final [0] -- necessary because getElementsByTagName returns a collection.

            This was the only safe way I found because of the !@#$* on-the-fly IDs.

            I think all fireResourceFormChange() does is enable the "Save" button, so you only have to call it once, but I'm not sure (I'm never sure of anything with modExt). 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