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

JavaScript inside "Formatted HTML" stop work, when Groovy script uses a value of another parameter

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • active-choices-plugin
    • None
    • Windows 10 64 bit
      java.version 1.8.0_162
      Tomcat 9.0.34
      Jenkins 2.254
      Active Choices 2.4
      Firefox 79.0

      Here is two parameters:

      Param1 - simple single select:

      return ['value1', 'value2']
      

      Param2 - formatted HTML:

      def tst = "new"
      html = '''
      <html>
      <body>
      <input type="checkbox" onClick="Result(this)" /> Select all<br/>
      <input type="checkbox" name="cbx" value="One" onClick="Result()"/> One<br/>
      <input type="checkbox" name="cbx" value="Two" onClick="Result()"/> Two<br/>
      <input type="checkbox" name="cbx" value="Three" onClick="Result()"/> Three<br/>
      <script>
      function Result(source) {
      	var checkboxes = document.getElementsByName("cbx");
      	var result = document.getElementById("result");
      	result.value = "";
      	for(var i=0, n=checkboxes.length;i<n;i++) {
      		if (source) checkboxes[i].checked = source.checked;
      		if (checkboxes[i].checked) result.value = result.value + checkboxes[i].value + ",";
      	}  
      	result.value = result.value + "''' + tst + '''";
      }
      </script>
      <input type="text" id = "result" name="value" value="''' + tst + '''">
      </body>
      </html>
      '''
      return html
      

      When Param2 does not use Param1 value, function Result works great:


      But when I try to use value of Param1, JavaScript does not work:

      def tst = Param1
      

       

          [JENKINS-63509] JavaScript inside "Formatted HTML" stop work, when Groovy script uses a value of another parameter

          Vladimir Buravtsov created issue -
          Vladimir Buravtsov made changes -
          Description Original: Here is two parameters:

          Param1 - simple single select:
          {code:java}
          return ['value1', 'value2']
          {code}
          !image-2020-08-26-16-53-51-594.png|width=300,height=400!

          Param2 - formatted HTML:
          {code:java}
          def tst = "new"
          html = '''
          <html>
          <body>
          <input type="checkbox" onClick="Result(this)" /> Выбрать все<br/>
          <input type="checkbox" name="cbx" value="One" onClick="Result()"/> One<br/>
          <input type="checkbox" name="cbx" value="Two" onClick="Result()"/> Two<br/>
          <input type="checkbox" name="cbx" value="Three" onClick="Result()"/> Three<br/>
          <script>
          function Result(source) {
          var checkboxes = document.getElementsByName("cbx");
          var result = document.getElementById("result");
          result.value = "";
          for(var i=0, n=checkboxes.length;i<n;i++) {
          if (source) checkboxes[i].checked = source.checked;
          if (checkboxes[i].checked) result.value = result.value + checkboxes[i].value + ",";
          }
          result.value = result.value + "''' + tst + '''";
          }
          </script>
          <input type="text" id = "result" name="value" value="''' + tst + '''">
          </body>
          </html>
          '''
          return html
          {code}
          !image-2020-08-26-17-01-10-341.png|width=300,height=400!

          When Param2 does not use Param1 value, function Result works great:

          !image-2020-08-26-17-07-27-385.png!!image-2020-08-26-17-08-16-520.png!
           But when I try to use value of Param1, JavaScript does not work:
          {code:java}
          def tst = Param1
          {code}
            !image-2020-08-26-17-12-04-412.png!
          New: Here is two parameters:

          Param1 - simple single select:
          {code:java}
          return ['value1', 'value2']
          {code}
          !image-2020-08-26-16-53-51-594.png|width=300,height=400!

          Param2 - formatted HTML:
          {code:java}
          def tst = "new"
          html = '''
          <html>
          <body>
          <input type="checkbox" onClick="Result(this)" /> Select all<br/>
          <input type="checkbox" name="cbx" value="One" onClick="Result()"/> One<br/>
          <input type="checkbox" name="cbx" value="Two" onClick="Result()"/> Two<br/>
          <input type="checkbox" name="cbx" value="Three" onClick="Result()"/> Three<br/>
          <script>
          function Result(source) {
          var checkboxes = document.getElementsByName("cbx");
          var result = document.getElementById("result");
          result.value = "";
          for(var i=0, n=checkboxes.length;i<n;i++) {
          if (source) checkboxes[i].checked = source.checked;
          if (checkboxes[i].checked) result.value = result.value + checkboxes[i].value + ",";
          }
          result.value = result.value + "''' + tst + '''";
          }
          </script>
          <input type="text" id = "result" name="value" value="''' + tst + '''">
          </body>
          </html>
          '''
          return html
          {code}
          !image-2020-08-26-17-01-10-341.png|width=300,height=400!

          When Param2 does not use Param1 value, function Result works great:

          !image-2020-08-26-17-07-27-385.png!!image-2020-08-26-17-08-16-520.png!
           But when I try to use value of Param1, JavaScript does not work:
          {code:java}
          def tst = Param1
          {code}
            !image-2020-08-26-17-12-04-412.png!
          Vladimir Buravtsov made changes -
          Attachment New: image-2020-08-26-17-30-26-600.png [ 52441 ]
          Vladimir Buravtsov made changes -
          Attachment New: image-2020-08-26-17-33-24-921.png [ 52442 ]
          Bruno P. Kinoshita made changes -
          Link New: This issue duplicates JENKINS-69045 [ JENKINS-69045 ]
          Bruno P. Kinoshita made changes -
          Attachment New: image-2024-10-08-23-39-17-983.png [ 63386 ]

            kinow Bruno P. Kinoshita
            ngagex Vladimir Buravtsov
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: