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
    You can put placeholder tags for the current values in the form and set them in a snippet that runs when the form loads.

    That way, the current values for all fields will be saved unless the user changes something.
      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
      • 19599
      • 33 Posts
      Quote from: BobRay at Feb 17, 2014, 01:02 PM
      You can put placeholder tags for the current values in the form and set them in a snippet that runs when the form loads.

      That way, the current values for all fields will be saved unless the user changes something.

      Hi Bob, that is an idea, I saw there is already a hidden field with something like "tvdef1" (integer increases depending on where the tv is placed). But is there no way I can use MODext to create an object for my own TV with my values and have it save it on form submit?
        • 3749
        • 24,544 Posts
        I'm sure you can do that, but how would modExt know what the TV's value is? It's running in your browser and has no easy way of finding out the TV's value. That means you would have to either create a processor to get the TV value and make an Ajax call to it, or use PHP to modify the modxExt code before it gets to the browser.

        In either case, just having a snippet set a placeholder with the TV value would be a lot easier and more efficient. Here's the entire snippet:

        $tvValue = $modx->resource->getTVValue('TvName');
        $modx->setPlaceholder('TvName', $tvValue);
          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
          • 19599
          • 33 Posts
          Quote from: BobRay at Feb 18, 2014, 12:16 PM
          I'm sure you can do that, but how would modExt know what the TV's value is? It's running in your browser and has no easy way of finding out the TV's value. That means you would have to either create a processor to get the TV value and make an Ajax call to it, or use PHP to modify the modxExt code before it gets to the browser.

          In either case, just having a snippet set a placeholder with the TV value would be a lot easier and more efficient. Here's the entire snippet:

          $tvValue = $modx->resource->getTVValue('TvName');
          $modx->setPlaceholder('TvName', $tvValue);

          I think my question is not written properly: When I load the Resourve Page with my TV on it everything works fine. I do get the TV Values from the TvInputRenderer and can initialize my Javascript object with the data. Also changing and storing back to the DB works fine. However, as my custom TV does not use MODext Objects and probably does not render the needed DOM tags, when I hit the save button on the top of the resource page, the MODext that generated that page somehow tries to serialize my TV's values. And since it can't find anything there it saves NULL to the database, hence overwritting my previously stored information.
          Now my question is, how do I hook into this Save Mechanism of my resource page, so my TV value does not get reset to NULL?
            • 4172
            • 5,888 Posts

            I followed these things and managed to get it to work just fine. However there is one last issue I can't get to: My Custom Upload TV now saves directly upon successfully adding the files. If the user now hits Save on the top of the page, my TV of course appears empty and NULL is written to the database. How do I either pass the proper data format to the request, that saves the page or how can I get ignored, so my already saved TV values are not overwritten?

            can't you get the TV-Value with a plugin, that runs on the system-event OnDocFormSave and set the correct value, before modx saves it to the db?
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
            • discuss.answer
              • 19599
              • 33 Posts
              I finally figured it out. There is a lot of magic happening inside MODx, maybe almost a little to much, and it's hard to figure it all out if you are not using MODext to create your UI. ;-)

              So, I placed a hidden input field with
              <input type="hidden" id="tv{$tv->id}" name="tv{$tv->id}" value="" />
              


              and I keep the value updated from within my Javascript Object. What I did not understand from the documentation is, that MODx will automatically save the data from input fields labeled that way and also initialise the input field on load with the stored TV data.

              And as a tip for anybody who tries to develop tv input everytime you change the value on your own markup, call MODx.fireResourceFormChange(); (this will enable the save button on the top)

              Thanks a lot for your continuos support Bob and Bruno, appreciate it!