Gen Web View HTML Control custom button does not work
search cancel

Gen Web View HTML Control custom button does not work

book

Article ID: 210067

calendar_today

Updated On:

Products

Gen - Workstation Toolset Gen

Issue/Introduction

An HTML Control custom button is coded with same ID as the html code generated for a Gen Window designed "ok" button. The custom button executes the Gen "ok" button function successfully in Web Generation but does nothing in Web View.

Environment

Release : 8.6
Component : ECLIPSE WEB VIEW

Resolution

Web View is different to Web Generation because an iframe is used for each custom HTML Control to separate it from the main Gen page and other HTML Controls to avoid any unexpected conflicts.
Due to the use of iframes the custom HTML Control defined button is not aware of the Gen button and it needs to "Traverse the DOM" 
The following example shows how a custom HTML Control containing a button "TestOK" uses a clickFunction() to enable it to execute the Gen button "ok".
Note: It was found that due to dynamic changes to the button ID the ID itself could not be used so instead of using "getElementById" the approach is to use "getElementsByTagName".

<button id="gen-Button1" name="Button1" class="Button1 gen_button regbutton" type="button" onclick="clickFunction()" >TestOK</button>
<script>
function clickFunction() {
         // Search for element/button in DOM and click 
   
         // get the button elements from the doc we want
         var genbuttons = parent.document.getElementsByTagName('button');
   
         // iterate to find which one of the buttons we want to use
         for ( x= 0; x < genbuttons.length; x++ ) { // we want Gen button to click for the one whose label/text is "ok"
             if ("ok" == genbuttons[x].innerText) {
                  // this is the button we needed.
                  genbuttons[x].click();
                 }
            }
    }
</script>