We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4018
    • 1,131 Posts
    Hey Raymond,

    Got a challenge for you!! Perhaps you can help me out with this. While working more on the Xinha plugin, it occurred to me that I needed a small javascript function to run when the system configuration settings page is submitted. Problem is...there doesn’t appear to be any way to add a function to the OnSubmit part of the Save button. So....do you think there is a way to modify the plugin and/or system settings functionality to allow adding a javascript function to OnSubmit? Definitely would help out alot with plugin development! smiley

    L8R!

    Jeff
      Jeff Whitfield

      "I like my coffee hot and strong, like I like my women, hot and strong... with a spoon in them."
      • 32963
      • 1,732 Posts
      try this:

      <script>
      var f = document.settings;
      var evt = f.onsubmit;
      f.onsubmit = function(event) {
      // run your code here
      if(evt && typeof(evt)==’function’) evt(event);
      }
      </script>
        xWisdom
        www.xwisdomhtml.com
        The fear of the Lord is the beginning of wisdom:
        MODx Co-Founder - Create and do more with less.
        • 4018
        • 1,131 Posts
        Ok...not sure if I’m doing this correctly. This is what I have in my code:

        		var f  = document.settings;
        		var evt = f.onsubmit;
        		f.onsubmit = function(event) {
        			// run your code here
        			var chks = f.getElementsByName('xinha_plugins_selected');
        			for (var i = 0; i < chks.length; i++){
        				if (!chks[i].checked){
        					chks[i].value = 'none';
        				}
        			if(evt && typeof(evt)=='function') evt(event);
        		}
        


        Here’s the skinny. I have an array of checkboxes with the name xinha_plugins_selected[]. Each checkbox represents a specific plugin and the value set as the name of the plugin. The idea is that a simple array of the selected plugins is stored in the system settings for that variable. The main reason I did it like this is due to the fact that plugins will likely change and new plugins might be added.

        Here’s the problem though. Once a plugin (or plugins) has been selected and the system settings are saved, the plugin is indeed selected once I go back into the configuration settings. No problem there. However, if I unselect all plugins and hit Save the new settings aren’t saved. Basically it’s a problem with the xinha_plugins_selected form array having an empty value...the script basically doesn’t see it and the current value isn’t changed in the database. So...what I understand must be done is to force the script to see the form variable and assign it a value of some sort. That’s what the script is for. It’s supposed to check to see if any checkboxes are checked and, if not, sets the value to "none". However, doesn’t appear that it’s happening. sad

        Although I think it would be good to have a consistent way of running javascript code on form submission, there is a workaround. I can always create a hidden input value and set it to something...that way the form will always see a value for the array....but it would still be nice to have an alternative. smiley
          Jeff Whitfield

          "I like my coffee hot and strong, like I like my women, hot and strong... with a spoon in them."
          • 32963
          • 1,732 Posts
          How about adding a checkbox Labeled "None". This way the server can select the "None" check box (with the value none) to clear all the other checkboxes.

          You might also want to have a look at the javascript using for selecting document groups inside mutate_content.dynamic.php
            xWisdom
            www.xwisdomhtml.com
            The fear of the Lord is the beginning of wisdom:
            MODx Co-Founder - Create and do more with less.
            • 4018
            • 1,131 Posts
            Quote from: xwisdom at Aug 31, 2005, 09:44 AM

            How about adding a checkbox Labeled "None". This way the server can select the "None" check box (with the value none) to clear all the other checkboxes.

            Good idea...like, duh, why didn’t I think of that! wink
              Jeff Whitfield

              "I like my coffee hot and strong, like I like my women, hot and strong... with a spoon in them."