Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-42034

Reactive Reference parameter with Formated HTML loses script section when binding to other build parameters

    • Icon: Task Task
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • active-choices-plugin
    • None
    • Jenkins 2.32.2, Active Choices 1.5.2, Chrome v. 56

      Using an Active Choices Reactive Reference Parameter and having it return Formatted HTML with a script portion (onchange, etc...) works great unless the groovy script references other dependent build parameters such as strings, Active Choice parameters, etc... The returned HTML renders properly, just without the script. Attached is a (hopefully) very simple job configuration to demonstrate.

      The groovy script for generating the sample test is as follows (DummyVar is a string parameter defined just above this parameter):

      //Uncomment this line, causing DummyVar to be referenced, and the script will be lost at runtime.
      //def a = DummyVar
      
      def FullHTML = ""
      FullHTML += "<head>"
      FullHTML += "<script type='text/javascript'> jQuery(document).on('ready', function() {	function updateOutputValue()  { jQuery('#value').val('Booya!');     };"
      FullHTML += " updateOutputValue();"
      FullHTML += "});"
      FullHTML += "</script>"
      FullHTML += "</head>"
      FullHTML += "<body><form><input id='value' name='value' > </form></body>"
      return FullHTML
      

        1. image-2017-06-01-22-48-32-552.png
          image-2017-06-01-22-48-32-552.png
          13 kB
        2. image-2017-06-01-22-46-45-391.png
          image-2017-06-01-22-46-45-391.png
          11 kB
        3. config-5-4-2017.xml
          8 kB
        4. config-doubleload.xml
          7 kB
        5. config.xml
          4 kB
        6. screenshot-1.png
          screenshot-1.png
          12 kB
        7. config[1].xml
          5 kB
        8. config.xml
          4 kB

          [JENKINS-42034] Reactive Reference parameter with Formated HTML loses script section when binding to other build parameters

          Bill Matzen created issue -
          Bruno P. Kinoshita made changes -
          Description Original: Using an Active Choices Reactive Reference Parameter and having it return Formatted HTML with a script portion (onchange, etc...) works great unless the groovy script references other dependent build parameters such as strings, Active Choice parameters, etc... The returned HTML renders properly, just without the script. Attached is a (hopefully) very simple job configuration to demonstrate.

          The groovy script for generating the sample test is as follows (DummyVar is a string parameter defined just above this parameter):

          -----------------------------------------------------------------------------------
          //Uncomment this line, causing DummyVar to be referenced, and the script will be lost at runtime.
          //def a = DummyVar

          def FullHTML = ""
          FullHTML += "<head>"
          FullHTML += "<script type='text/javascript'> jQuery(document).on('ready', function() { function updateOutputValue() { jQuery('#value').val('Booya!'); };"
          FullHTML += " updateOutputValue();"
          FullHTML += "});"
          FullHTML += "</script>"
          FullHTML += "</head>"
          FullHTML += "<body><form><input id='value' name='value' > </form></body>"
          return FullHTML
          -----------------------------------------------------------------------------------
          New: Using an Active Choices Reactive Reference Parameter and having it return Formatted HTML with a script portion (onchange, etc...) works great unless the groovy script references other dependent build parameters such as strings, Active Choice parameters, etc... The returned HTML renders properly, just without the script. Attached is a (hopefully) very simple job configuration to demonstrate.

          The groovy script for generating the sample test is as follows (DummyVar is a string parameter defined just above this parameter):

          {code}
          //Uncomment this line, causing DummyVar to be referenced, and the script will be lost at runtime.
          //def a = DummyVar

          def FullHTML = ""
          FullHTML += "<head>"
          FullHTML += "<script type='text/javascript'> jQuery(document).on('ready', function() { function updateOutputValue() { jQuery('#value').val('Booya!'); };"
          FullHTML += " updateOutputValue();"
          FullHTML += "});"
          FullHTML += "</script>"
          FullHTML += "</head>"
          FullHTML += "<body><form><input id='value' name='value' > </form></body>"
          return FullHTML
          {code}

          I'm not sure referencing the parameter is the problem. Your script is returning HTML with a <script> tag. The plug-in includes the HTML you provided using innerHTML. That may be the problem.

          ioannis has way more experience than I using JavaScript with the reactive parameters. Ioannis, could you take a look at this script, please? Would be great if you could confirm it there's a bug in the plug-in behaviour. Looking at the code, I can't really understand what's going on, except that script tag is never evaluated, as far as I can tell.

          Bruno P. Kinoshita added a comment - I'm not sure referencing the parameter is the problem. Your script is returning HTML with a <script> tag. The plug-in includes the HTML you provided using innerHTML. That may be the problem. ioannis has way more experience than I using JavaScript with the reactive parameters. Ioannis, could you take a look at this script, please? Would be great if you could confirm it there's a bug in the plug-in behaviour. Looking at the code, I can't really understand what's going on, except that script tag is never evaluated, as far as I can tell.
          Bruno P. Kinoshita made changes -
          Assignee Original: Bruno P. Kinoshita [ kinow ] New: Ioannis Moutsatsos [ ioannis ]
          Ioannis Moutsatsos made changes -
          Attachment New: config[1].xml [ 36404 ]
          Ioannis Moutsatsos made changes -
          Attachment New: screenshot-1.png [ 36405 ]

          kinow I think this works as expected. I have attached a new config[1].xml where I simplified the 'ScriptVariables' parameter script so I can easily explain what I think it's going on.

          Here is the simplified script:

           

          def a = DummyVar
          
          def FullHTML = """
          <script type='text/javascript'> 
          jQuery(document).on('ready', function() {	function updateOutputValue() { jQuery('#value').val('Booya!'); };
          updateOutputValue();
          });
          </script>
          <input id='value' name="value" type="text" class="setting-input " value="$a">
          """
          
          return FullHTML
          

          The original script assigned a value through the jQuery selector on page load

          That is the key point I think. The page load script only runs when the build form is first loaded. Not when the parameter is refreshed on a cascade event.

          So if you are not referencing another parameter the page loads and the script sets the value to 'Booya'. However, if you are referencing another parameter it triggers an update event as soon as the DummyVar is set. Since the original script did not use the DummyVar then the returned <input> value was null.

          In this example, where I'm using the DummyVar value you see that it updates the <input> value to the DummyVar value

          Ioannis Moutsatsos added a comment - kinow I think this works as expected. I have attached a new config [1] .xml where I simplified the ' ScriptVariables ' parameter script so I can easily explain what I think it's going on. Here is the simplified script:   def a = DummyVar def FullHTML = """ <script type= 'text/javascript' > jQuery(document).on( 'ready' , function() { function updateOutputValue() { jQuery( '#value' ).val( 'Booya!' ); }; updateOutputValue(); }); </script> <input id= 'value' name= "value" type= "text" class= "setting-input " value= "$a" > """ return FullHTML The original script assigned a value through the jQuery selector on page load .  That is the key point I think. The page load script only runs when the build form is first loaded . Not when the parameter is refreshed on a cascade event. So if you are not referencing another parameter the page loads and the script sets the value to 'Booya'. However, if you are referencing another parameter it triggers an update event as soon as the DummyVar is set. Since the original script did not use the DummyVar then the returned <input> value was null. In this example, where I'm using the DummyVar value you see that it updates the <input> value to the DummyVar value
          Ioannis Moutsatsos made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Ioannis Moutsatsos made changes -
          Resolution New: Not A Defect [ 7 ]
          Status Original: In Progress [ 3 ] New: Closed [ 6 ]

          Bruno P. Kinoshita added a comment - - edited

          Great explanation - as always - Ioannis. Thanks for taking a look at this issue. I think we can mark it as Won't Fix (you were faster than me ), and wait for bmatzen's feedback.

          ps: Releasing 1.5.3 to update centre in 15 minutes

          Bruno P. Kinoshita added a comment - - edited Great explanation - as always - Ioannis. Thanks for taking a look at this issue. I think we can mark it as Won't Fix (you were faster than me ), and wait for bmatzen 's feedback. ps: Releasing 1.5.3 to update centre in 15 minutes

            ioannis Ioannis Moutsatsos
            bmatzen Bill Matzen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: